diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 35e03e9..b497d90 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -2,11 +2,13 @@ namespace App\Models; +use App\Services\Cache\CacheServiceInterface; use App\Traits\LogsActivity; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Support\Facades\DB; use Tymon\JWTAuth\Contracts\JWTSubject; class Customer extends Authenticatable implements JWTSubject @@ -15,6 +17,16 @@ class Customer extends Authenticatable implements JWTSubject protected $table = 'customers'; + protected static function booted(): void + { + $flushRepositoryCache = fn () => DB::afterCommit( + fn () => app(CacheServiceInterface::class)->clearByModule('customer') + ); + static::saved($flushRepositoryCache); + static::deleted($flushRepositoryCache); + static::restored($flushRepositoryCache); + } + /** * Chỉ định cột sẽ nhận UUID. * Mặc định HasUuids dùng cột 'id', mình đổi sang 'uuid'.