TDoG-Skin/app/Observers/ScopeObserver.php

38 lines
668 B
PHP
Raw Permalink Normal View History

2024-08-17 18:43:48 +08:00
<?php
namespace App\Observers;
use App\Models\Scope;
use Illuminate\Support\Facades\Cache;
class ScopeObserver
{
/**
* Handle the Scope "saved" event.
*
* @return void
*/
public function saved()
{
$this->refreshCachedScopes();
}
/**
* Handle the Scope "deleted" event.
*
* @return void
*/
public function deleted()
{
$this->refreshCachedScopes();
}
protected function refreshCachedScopes()
{
Cache::forget('scopes');
Cache::rememberForever('scopes', function () {
return Scope::pluck('description', 'name')->toArray();
});
}
}