From 938775e6fe8fb69ea552365dc71273929e4f792b Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 1 Sep 2022 16:35:25 +0200 Subject: [PATCH] Add instruction to reset cache key on TenancyEnded --- source/docs/v3/integrations/spatie.blade.md | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/docs/v3/integrations/spatie.blade.md b/source/docs/v3/integrations/spatie.blade.md index 53be3bc..674602c 100644 --- a/source/docs/v3/integrations/spatie.blade.md +++ b/source/docs/v3/integrations/spatie.blade.md @@ -26,19 +26,16 @@ php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvid mv database/migrations/*_create_permission_tables.php database/migrations/tenant ``` -Then add this to your `AppServiceProvider::boot()` method: +Then add this to your `TenancyServiceProvider::boot()`: ```php Event::listen(TenancyBootstrapped::class, function (TenancyBootstrapped $event) { - // TenancyBootstraped event is called if you are creating tenants through the central app, - // so to prevent making caches with wrong permissions the code below can be used - // - // $isACentralDomain = in_array(request()->getHost(), config('tenancy.central_domains'), true); - // if(!$isACentralDomain) { - // \Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache.tenant.' . $event->tenancy->tenant->id; - // } \Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache.tenant.' . $event->tenancy->tenant->id; }); + +Event::listen(TenancyEnded::class, function (TenancyEnded $event) { + \Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache'; +}); ``` The reason for this is that spatie/laravel-permission caches permissions & roles to save DB queries, which means that we need to separate the permission cache by tenant.