fix: 🐛 reset cache when creating a news model

This commit is contained in:
Noah Lancien 2026-05-05 15:08:46 +02:00
parent 8893c793a5
commit 59fc3df7a5
2 changed files with 37 additions and 3 deletions

View file

@ -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();
}
}

35
app/Models/Newsable.php Normal file
View file

@ -0,0 +1,35 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\MorphPivot;
/**
* @property integer $id Id of the news.
* @property \App\Models\News $news_id Name of the news.
* @property \App\Models\NewsCategory|\App\Models\NewsTag $newsable_id Name of the category or tag.
* @property class-string<static> $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());
}
}