Update spatie.blade.md (#144)

* Update spatie.blade.md

When a tenant is created through the central app TenancyBootstraped is called and wrong permissions are cached if permissions between central and tenant apps are different.

* Add instruction to reset cache key on TenancyEnded

Co-authored-by: lukinovec <lukinovec@gmail.com>
This commit is contained in:
Svetlin Stoev 2022-09-01 18:08:25 +03:00 committed by GitHub
parent af05970907
commit 58cd62fab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,12 +29,16 @@ php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvid
mv database/migrations/*_create_permission_tables.php database/migrations/tenant 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 ```php
Event::listen(TenancyBootstrapped::class, function (TenancyBootstrapped $event) { Event::listen(TenancyBootstrapped::class, function (TenancyBootstrapped $event) {
\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. 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.