mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 10:14:03 +00:00
update spatie/laravel-permission integration guide to match 5.x
This commit is contained in:
parent
92a56bd0e2
commit
49941b625d
1 changed files with 25 additions and 2 deletions
|
|
@ -34,17 +34,40 @@ Next, add the following listeners to the `TenancyBootstrapped` and `TenancyEnde
|
||||||
```php
|
```php
|
||||||
Events\TenancyBootstrapped::class => [
|
Events\TenancyBootstrapped::class => [
|
||||||
function (Events\TenancyBootstrapped $event) {
|
function (Events\TenancyBootstrapped $event) {
|
||||||
\Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache.tenant.' . $event->tenancy->tenant->id;
|
$permissionRegistrar = app(\Spatie\Permission\PermissionRegistrar::class);
|
||||||
|
$permissionRegistrar->cacheKey = 'spatie.permission.cache.tenant.' . $event->tenancy->tenant->getTenantKey();
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
Events\TenancyEnded::class => [
|
Events\TenancyEnded::class => [
|
||||||
function (Events\TenancyEnded $event) {
|
function (Events\TenancyEnded $event) {
|
||||||
\Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache';
|
$permissionRegistrar = app(\Spatie\Permission\PermissionRegistrar::class);
|
||||||
|
$permissionRegistrar->cacheKey = 'spatie.permission.cache';
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Alternatively, create a bootstrapper:
|
||||||
|
|
||||||
|
```php
|
||||||
|
class SpatiePermissionsBootstrapper implements TenancyBootstrapper
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected PermissionRegistrar $registrar,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function bootstrap(Tenant $tenant): void
|
||||||
|
{
|
||||||
|
$this->registrar->cacheKey = 'spatie.permission.cache.tenant.' . $tenant->getTenantKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revert(): void
|
||||||
|
{
|
||||||
|
$this->registrar->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. We also need to reset the cache key when tenancy ends so that the tenant's cache key isn't used in the central app.
|
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. We also need to reset the cache key when tenancy ends so that the tenant's cache key isn't used in the central app.
|
||||||
|
|
||||||
## **laravel-medialibrary** {#laravel-medialibrary}
|
## **laravel-medialibrary** {#laravel-medialibrary}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue