Skip to content

Instantly share code, notes, and snippets.

@sauron
Created November 4, 2021 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauron/99fb4628666cacd3d9604c1afbe9934c to your computer and use it in GitHub Desktop.
Save sauron/99fb4628666cacd3d9604c1afbe9934c to your computer and use it in GitHub Desktop.
Event Listener registration for clearing the cache on save. Files: app/Listeners/TwillEventSubscriber.php and in app/Providers/EventServiceProvider.php
/**
* The subscriber classes to register.
*
* @var array
*/
protected $subscribe = [
'App\Listeners\TwillEventSubscriber',
];
<?php
namespace App\Listeners;
use Illuminate\Support\Facades\Cache;
use Spatie\ResponseCache\Facades\ResponseCache;
class TwillEventSubscriber
{
/**
* Handle settings saved.
*/
public static function handleSettingsSaved($event)
{
Cache::forget('setting.menu.header');
Cache::forget('setting.menu.footer');
ResponseCache::clear();
}
/**
* Register the listeners for the subscriber.
*
* @param \Illuminate\Events\Dispatcher $events
* @return void
*/
public function subscribe($events)
{
$events->listen(
'cms-settings.saved',
[TwillEventSubscriber::class, 'handleSettingsSaved']
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment