Created
November 4, 2021 13:21
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The subscriber classes to register. | |
* | |
* @var array | |
*/ | |
protected $subscribe = [ | |
'App\Listeners\TwillEventSubscriber', | |
]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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