diff --git a/resources/views/livewire/comments.blade.php b/resources/views/livewire/comments.blade.php
index 3764b17..19ddf14 100644
--- a/resources/views/livewire/comments.blade.php
+++ b/resources/views/livewire/comments.blade.php
@@ -6,7 +6,7 @@
{{-- Sort toggle --}}
- Comments ({{ $this->totalCount }})
+ Comments ({{ $this->allCommentsCount }})
@auth
diff --git a/src/Livewire/Comments.php b/src/Livewire/Comments.php
index bfbe6bc..da391de 100644
--- a/src/Livewire/Comments.php
+++ b/src/Livewire/Comments.php
@@ -80,6 +80,12 @@ class Comments extends Component implements HasForms
return $this->model->topLevelComments()->count();
}
+ #[Computed]
+ public function allCommentsCount(): int
+ {
+ return $this->model->commentCount();
+ }
+
#[Computed]
public function hasMore(): bool
{
@@ -203,7 +209,7 @@ class Comments extends Component implements HasForms
public function refreshComments(): void
{
- unset($this->comments, $this->totalCount, $this->hasMore);
+ unset($this->comments, $this->totalCount, $this->hasMore, $this->allCommentsCount);
}
public function render(): View
diff --git a/src/Models/Comment.php b/src/Models/Comment.php
index eb3714d..48eb5f5 100644
--- a/src/Models/Comment.php
+++ b/src/Models/Comment.php
@@ -28,6 +28,10 @@ class Comment extends Model
$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 {
$comment->attachments()->delete();
$comment->reactions()->delete();