#4: Added navigation properties to retrieved approved comments and comment owner. Started adding comments to the view.

This commit is contained in:
Andy Heathershaw 2018-09-17 22:30:27 +01:00
parent 0ebd7a1c5f
commit 1f7befafab
6 changed files with 37 additions and 11 deletions

View File

@ -52,6 +52,11 @@ class Photo extends Model
return $this->belongsTo(Album::class);
}
public function approvedComments()
{
return $this->hasMany(PhotoComment::class)->whereNotNull('approved_at');
}
public function exifUrl()
{
return route('viewExifData', [

View File

@ -16,4 +16,14 @@ class PhotoComment extends Model
'commentor_email',
'comment_text'
];
public function approvedBy()
{
return $this->belongsTo(User::class, 'approved_user_id');
}
public function createdBy()
{
return $this->belongsTo(User::class, 'created_user_id');
}
}

View File

@ -57,7 +57,7 @@
@endif
@if (UserConfig::get('allow_photo_comments'))
@include (Theme::viewName('partials.gallery_photo_comments'))
@include (Theme::viewName('partials.photo_comments'))
@endif
</div>

View File

@ -1,10 +0,0 @@
<div class="row">
<div class="col mt-4">
<h2>@lang('gallery.photo_comments_heading')</h2>
<h3>@lang('gallery.photo_comments_reply_form_heading')</h3>
<p>@lang('gallery.photo_comments_reply_form_p1')</p>
<hr/>
@include(Theme::viewName('gallery.photo_comments_reply_form'))
</div>
</div>

View File

@ -0,0 +1,21 @@
<div class="row">
<div class="col mt-4">
<h2>@lang('gallery.photo_comments_heading')</h2>
<h3>@lang('gallery.photo_comments_reply_form_heading')</h3>
<p>@lang('gallery.photo_comments_reply_form_p1')</p>
<hr/>
@include(Theme::viewName('partials.photo_comments_reply_form'))
@if ($photo->approvedComments()->count() > 0)
<ul>
@foreach ($photo->approvedComments as $comment)
<li>
Comment by <b>{{ $comment->createdBy->name }}</b>:<br/>
{{ $comment->comment_text }}
</li>
@endforeach
</ul>
@endif
</div>
</div>