From b9117b83078484dd0fb7a615c92ac2d813c4ee87 Mon Sep 17 00:00:00 2001 From: Anna Thomas Date: Tue, 12 Aug 2025 20:43:59 +0900 Subject: [PATCH 1/2] Fix comment count to match # of comments --- app/Livewire/Posts/PostIndexItemComponent.php | 2 +- app/Models/Post.php | 6 ++++++ resources/views/posts/partials/post-index-footer.blade.php | 2 +- resources/views/posts/partials/post-show-footer.blade.php | 2 +- resources/views/posts/show.blade.php | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Posts/PostIndexItemComponent.php b/app/Livewire/Posts/PostIndexItemComponent.php index e8a6c2f3..4529ca41 100644 --- a/app/Livewire/Posts/PostIndexItemComponent.php +++ b/app/Livewire/Posts/PostIndexItemComponent.php @@ -21,7 +21,7 @@ public function mount(Post $post): void { $this->authorizedUserId = $this->getAuthorizedUserId(); $this->post = $post; - $this->commentCount = $post->comments()->count(); + $this->commentCount = $post->commentsCount(); } public function render(): View diff --git a/app/Models/Post.php b/app/Models/Post.php index 2f76bf97..cef99a05 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -143,6 +143,12 @@ public function comments(): HasMany return $this->hasMany(Comment::class); } + public function commentsCount(): int + { + // Only count comments by regular users, not moderator actions + return $this->hasMany(Comment::class)->whereNull("moderation_type")->count(); + } + public function bookmarkCount(): int { return Bookmark::count($this); diff --git a/resources/views/posts/partials/post-index-footer.blade.php b/resources/views/posts/partials/post-index-footer.blade.php index d9d9985a..7a3da17f 100644 --- a/resources/views/posts/partials/post-index-footer.blade.php +++ b/resources/views/posts/partials/post-index-footer.blade.php @@ -9,6 +9,6 @@ href="{{ $post->present()->url }}#comments" title="{{ trans('Comments') }}"> - {{ $post->comments()->count() > 0 ?: 0 }} + {{ $post->commentsCount() }} diff --git a/resources/views/posts/partials/post-show-footer.blade.php b/resources/views/posts/partials/post-show-footer.blade.php index b3e86a60..3cd72baf 100644 --- a/resources/views/posts/partials/post-show-footer.blade.php +++ b/resources/views/posts/partials/post-show-footer.blade.php @@ -15,7 +15,7 @@ - {{ $commentsCount > 0 ?: 0 }} + {{ $commentsCount }} @if (isset($favoritesCount) && $favoritesCount > 0) diff --git a/resources/views/posts/show.blade.php b/resources/views/posts/show.blade.php index 789a41d8..25b2dbbe 100644 --- a/resources/views/posts/show.blade.php +++ b/resources/views/posts/show.blade.php @@ -42,7 +42,7 @@ @include('posts.partials.post-show-footer', [ 'post' => $post, - 'commentsCount' => $post->comments()->count(), + 'commentsCount' => $post->commentsCount(), 'favoritesCount' => $post->favoriteCount(), ]) From 952b5e29fccd80e4fafa9f194d7ee6d85da938d1 Mon Sep 17 00:00:00 2001 From: Anna Thomas Date: Tue, 12 Aug 2025 21:03:30 +0900 Subject: [PATCH 2/2] double to single quote --- app/Models/Post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Post.php b/app/Models/Post.php index cef99a05..913fd6fd 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -146,7 +146,7 @@ public function comments(): HasMany public function commentsCount(): int { // Only count comments by regular users, not moderator actions - return $this->hasMany(Comment::class)->whereNull("moderation_type")->count(); + return $this->hasMany(Comment::class)->whereNull('moderation_type')->count(); } public function bookmarkCount(): int