Changes
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Spatie\Tags\HasTags;
|
||||
|
||||
class Post extends Model
|
||||
@@ -15,6 +16,19 @@ class Post extends Model
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saved(function ($post) {
|
||||
Cache::forget('post_' . $post->id);
|
||||
Cache::forget('posts_' . $post->category_id . '_*'); // Очистка кеша для всех постов в категории
|
||||
});
|
||||
|
||||
static::deleted(function ($post) {
|
||||
Cache::forget('post_' . $post->id);
|
||||
Cache::forget('posts_' . $post->category_id . '_*'); // Очистка кеша для всех постов в категории
|
||||
});
|
||||
}
|
||||
|
||||
public function category() : BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
|
||||
Reference in New Issue
Block a user