This commit is contained in:
f4ilji
2025-01-15 15:31:37 +05:00
parent 45e73e27a0
commit bad611eb84
27 changed files with 815 additions and 124 deletions
+14
View File
@@ -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);