diff --git a/app/Models/Article.php b/app/Models/Article.php index 32c697b6..470d14eb 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -87,6 +87,13 @@ final class Article extends Model implements HasMedia, ReactableInterface, Sitem 'is_pinned' => 'boolean', ]; + protected static function booted(): void + { + Article::deleting(function ($article): void { + $article->activities()->delete(); + }); + } + protected bool $removeViewsOnDelete = true; public function getRouteKeyName(): string diff --git a/app/Models/Discussion.php b/app/Models/Discussion.php index cd96c408..664d9d39 100644 --- a/app/Models/Discussion.php +++ b/app/Models/Discussion.php @@ -80,6 +80,13 @@ final class Discussion extends Model implements ReactableInterface, ReplyInterfa protected bool $removeViewsOnDelete = true; + protected static function booted(): void + { + Discussion::deleting(function ($discussion): void { + $discussion->activities()->delete(); + }); + } + public function newEloquentBuilder($query): DiscussionQueryBuilder { return new DiscussionQueryBuilder($query); diff --git a/app/Models/Reply.php b/app/Models/Reply.php index a01f91fe..3b6dc36b 100644 --- a/app/Models/Reply.php +++ b/app/Models/Reply.php @@ -46,6 +46,13 @@ final class Reply extends Model implements ReactableInterface, ReplyInterface, S 'body', ]; + protected static function booted(): void + { + Reply::deleting(function ($reply): void { + $reply->activities()->delete(); + }); + } + public function subject(): int { return $this->id; diff --git a/app/Models/Thread.php b/app/Models/Thread.php index 6e5573cc..2fed8698 100644 --- a/app/Models/Thread.php +++ b/app/Models/Thread.php @@ -84,6 +84,13 @@ final class Thread extends Model implements Feedable, ReactableInterface, ReplyI protected bool $removeViewsOnDelete = true; + protected static function booted(): void + { + Thread::deleting(function ($thread): void { + $thread->activities()->delete(); + }); + } + public function getRouteKeyName(): string { return 'slug'; diff --git a/composer.lock b/composer.lock index f79cb730..d2a35e46 100644 --- a/composer.lock +++ b/composer.lock @@ -4200,16 +4200,16 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - }, "laravel": { - "providers": [ - "Jenssegers\\Agent\\AgentServiceProvider" - ], "aliases": { "Agent": "Jenssegers\\Agent\\Facades\\Agent" - } + }, + "providers": [ + "Jenssegers\\Agent\\AgentServiceProvider" + ] + }, + "branch-alias": { + "dev-master": "3.0-dev" } }, "autoload": {