multitenacy combined with tenancyforlaravel and filament shield permission problem

Hello all,

I have a a problem with the permissions of filament shield. When i run the shield:generate on the admin app all is working for the admin. But then when I run the shield:generate for the tenant (different database) with tenants:run … the permissions are ok for the tenant but not anymore for the admin.

I think it has something todo with the caching of the permissions.

So two quesions:

Is there a way to disable the caching of the permission for testing purpose?

Is there a way to cache the permissions for a panel?


I hope someone knows the answer 😬

Thanks already
Solution
  1. To disable cache in dev mode set the CACHE_DRIVER=array in .env file or set the cache store to array from permission config file. learn more https://spatie.be/docs/laravel-permission/v5/advanced-usage/cache
  2. since you are using that package you need to add the following in TenancyServiceProvider
    ```php
    Events\TenancyBootstrapped::class => [
    function (Events\TenancyBootstrapped $event) {
    \Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache.tenant.' . $event->tenancy->tenant->id;
    }
    ],
Events\TenancyEnded::class => [
function (Events\TenancyEnded $event) {
\Spatie\Permission\PermissionRegistrar::$cacheKey = 'spatie.permission.cache';
}
],
```
learn more https://tenancyforlaravel.com/docs/v3/integrations/spatie
Was this page helpful?