From 59fc3df7a5acb92f0b3508c59b213959c8a5aa41 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Tue, 5 May 2026 15:08:46 +0200 Subject: [PATCH] fix: :bug: reset cache when creating a news model --- app/Models/News.php | 5 ++--- app/Models/Newsable.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/Models/Newsable.php diff --git a/app/Models/News.php b/app/Models/News.php index e6f01306..d0a58ac2 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -67,7 +67,6 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable, Sit use HasFactory; use HasTranslations; use SoftDeletes; - use HasCache; use HasUwilImages { HasUwilImages::inertiaFill as traitInertiaFill; } @@ -528,7 +527,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable, Sit 'newsables', 'news_id', 'newsable_id' - ); + )->using(Newsable::class); } /** @@ -544,6 +543,6 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable, Sit 'newsables', 'news_id', 'newsable_id' - )->withTimestamps(); + )->using(Newsable::class)->withTimestamps(); } } diff --git a/app/Models/Newsable.php b/app/Models/Newsable.php new file mode 100644 index 00000000..dc488445 --- /dev/null +++ b/app/Models/Newsable.php @@ -0,0 +1,35 @@ + $newsable_type Class of the category or tag. + * @property-read \Carbon\Carbon $created_at Created date of the news. + * @property-read \Carbon\Carbon $updated_at Updated date of the news. + */ +class Newsable extends MorphPivot +{ + /** + * The table associated with the model. + * + * @var string|null + */ + protected $table = 'newsables'; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::created(fn() => News::resetCache()); + static::updated(fn() => News::resetCache()); + static::deleted(fn() => News::resetCache()); + } +}