From 1f7befafab6c99d8b1a715b1164c5328eaf78903 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Mon, 17 Sep 2018 22:30:27 +0100 Subject: [PATCH] #4: Added navigation properties to retrieved approved comments and comment owner. Started adding comments to the view. --- app/Photo.php | 5 +++++ app/PhotoComment.php | 10 +++++++++ .../views/themes/base/gallery/photo.blade.php | 2 +- .../partials/gallery_photo_comments.blade.php | 10 --------- .../base/partials/photo_comments.blade.php | 21 +++++++++++++++++++ .../photo_comments_reply_form.blade.php | 0 6 files changed, 37 insertions(+), 11 deletions(-) delete mode 100644 resources/views/themes/base/partials/gallery_photo_comments.blade.php create mode 100644 resources/views/themes/base/partials/photo_comments.blade.php rename resources/views/themes/base/{gallery => partials}/photo_comments_reply_form.blade.php (100%) diff --git a/app/Photo.php b/app/Photo.php index bf224ff..37e90a6 100644 --- a/app/Photo.php +++ b/app/Photo.php @@ -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', [ diff --git a/app/PhotoComment.php b/app/PhotoComment.php index 293b477..dec829a 100644 --- a/app/PhotoComment.php +++ b/app/PhotoComment.php @@ -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'); + } } \ No newline at end of file diff --git a/resources/views/themes/base/gallery/photo.blade.php b/resources/views/themes/base/gallery/photo.blade.php index 61fcc74..d945288 100644 --- a/resources/views/themes/base/gallery/photo.blade.php +++ b/resources/views/themes/base/gallery/photo.blade.php @@ -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 diff --git a/resources/views/themes/base/partials/gallery_photo_comments.blade.php b/resources/views/themes/base/partials/gallery_photo_comments.blade.php deleted file mode 100644 index 0f553c3..0000000 --- a/resources/views/themes/base/partials/gallery_photo_comments.blade.php +++ /dev/null @@ -1,10 +0,0 @@ -
-
-

@lang('gallery.photo_comments_heading')

- -

@lang('gallery.photo_comments_reply_form_heading')

-

@lang('gallery.photo_comments_reply_form_p1')

-
- @include(Theme::viewName('gallery.photo_comments_reply_form')) -
-
\ No newline at end of file diff --git a/resources/views/themes/base/partials/photo_comments.blade.php b/resources/views/themes/base/partials/photo_comments.blade.php new file mode 100644 index 0000000..d4a9445 --- /dev/null +++ b/resources/views/themes/base/partials/photo_comments.blade.php @@ -0,0 +1,21 @@ +
+
+

@lang('gallery.photo_comments_heading')

+ +

@lang('gallery.photo_comments_reply_form_heading')

+

@lang('gallery.photo_comments_reply_form_p1')

+
+ @include(Theme::viewName('partials.photo_comments_reply_form')) + + @if ($photo->approvedComments()->count() > 0) +
    + @foreach ($photo->approvedComments as $comment) +
  • + Comment by {{ $comment->createdBy->name }}:
    + {{ $comment->comment_text }} +
  • + @endforeach +
+ @endif +
+
\ No newline at end of file diff --git a/resources/views/themes/base/gallery/photo_comments_reply_form.blade.php b/resources/views/themes/base/partials/photo_comments_reply_form.blade.php similarity index 100% rename from resources/views/themes/base/gallery/photo_comments_reply_form.blade.php rename to resources/views/themes/base/partials/photo_comments_reply_form.blade.php