fix: include replies in comment count and cascade delete to replies

This commit is contained in:
ilyapashayan
2026-03-30 18:59:07 +04:00
parent 20dba18e8e
commit 812556cba2
3 changed files with 12 additions and 2 deletions

View File

@@ -6,7 +6,7 @@
{{-- Sort toggle --}} {{-- Sort toggle --}}
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300"> <h3 class="text-sm font-medium text-gray-700 dark:text-gray-300">
Comments ({{ $this->totalCount }}) Comments ({{ $this->allCommentsCount }})
</h3> </h3>
@auth @auth
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">

View File

@@ -80,6 +80,12 @@ class Comments extends Component implements HasForms
return $this->model->topLevelComments()->count(); return $this->model->topLevelComments()->count();
} }
#[Computed]
public function allCommentsCount(): int
{
return $this->model->commentCount();
}
#[Computed] #[Computed]
public function hasMore(): bool public function hasMore(): bool
{ {
@@ -203,7 +209,7 @@ class Comments extends Component implements HasForms
public function refreshComments(): void public function refreshComments(): void
{ {
unset($this->comments, $this->totalCount, $this->hasMore); unset($this->comments, $this->totalCount, $this->hasMore, $this->allCommentsCount);
} }
public function render(): View public function render(): View

View File

@@ -28,6 +28,10 @@ class Comment extends Model
$comment->body = Str::sanitizeHtml($comment->body); $comment->body = Str::sanitizeHtml($comment->body);
}); });
static::deleting(function (self $comment): void {
$comment->replies()->each(fn ($reply) => $reply->delete());
});
static::forceDeleting(function (self $comment): void { static::forceDeleting(function (self $comment): void {
$comment->attachments()->delete(); $comment->attachments()->delete();
$comment->reactions()->delete(); $comment->reactions()->delete();