TDoG-Skin/app/Observers/ScopeObserver.php
2024-08-17 19:13:54 +08:00

38 lines
668 B
PHP
Executable File

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