Skip to content

Commit

Permalink
Add cache forget model observer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvenga committed Dec 11, 2022
1 parent 6921bda commit 37a821c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/LaravelSiteSettingsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace VI\LaravelSiteSettings;

use Illuminate\Support\ServiceProvider;
use VI\LaravelSiteSettings\Models\LaravelSiteSetting;
use VI\LaravelSiteSettings\Models\LaravelSiteSettingGroup;
use VI\LaravelSiteSettings\Observers\LSSObserver;

class LaravelSiteSettingsProvider extends ServiceProvider
{
Expand Down Expand Up @@ -30,9 +33,12 @@ public function boot()
__DIR__ . '/../stubs/MoonShine/Resources/LaravelSiteSettingResource.php.stub' => app_path('MoonShine/Resources/LaravelSiteSettingResource.php'),
], 'moonshine');

$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

}

$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
LaravelSiteSetting::observe(LSSObserver::class);
LaravelSiteSettingGroup::observe(LSSObserver::class);

}

Expand Down
38 changes: 38 additions & 0 deletions src/Observers/LSSObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace VI\LaravelSiteSettings\Observers;

use Illuminate\Database\Eloquent\Model;

class LSSObserver
{

public function created(Model $model)
{
cache()->forget(config('laravelsitesettings.cache_key'));
}


public function updated(Model $model)
{
cache()->forget(config('laravelsitesettings.cache_key'));
}


public function deleted(Model $model)
{
cache()->forget(config('laravelsitesettings.cache_key'));
}


public function restored(Model $model)
{
cache()->forget(config('laravelsitesettings.cache_key'));
}


public function forceDeleted(Model $model)
{
cache()->forget(config('laravelsitesettings.cache_key'));
}
}

0 comments on commit 37a821c

Please sign in to comment.