mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 10:14:03 +00:00
Add instruction to reset cache key on TenancyEnded
This commit is contained in:
parent
196ebaa5b6
commit
938775e6fe
1 changed files with 5 additions and 8 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue