Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Livewire/Posts/PostIndexItemComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/posts/partials/post-index-footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
href="{{ $post->present()->url }}#comments"
title="{{ trans('Comments') }}">
<x-icons.icon-component filename="chat" />
{{ $post->comments()->count() > 0 ?: 0 }}
{{ $post->commentsCount() }}
</a>
</footer>
2 changes: 1 addition & 1 deletion resources/views/posts/partials/post-show-footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<span>
<x-icons.icon-component filename="chat" />
{{ $commentsCount > 0 ?: 0 }}
{{ $commentsCount }}
</span>

@if (isset($favoritesCount) && $favoritesCount > 0)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/posts/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

@include('posts.partials.post-show-footer', [
'post' => $post,
'commentsCount' => $post->comments()->count(),
'commentsCount' => $post->commentsCount(),
'favoritesCount' => $post->favoriteCount(),
])
</article>
Expand Down