-
Hello, We have an application, using your laravel-permission package. We also have multitenant environment using this package: https://tenancyforlaravel.com/ We noticed, that we have a permissions cache issue. Permissions cache does not add a tenant id prefix tag, but it just takes a prefix from cache.php config. We have a cache bootstrapper, which gives a tenant id prefix to the cache keys. Spatie permissions cache does not seem to take this prefix. Has anyone seen or solved this "issue"? :) is there any work arounds? Thank you very much! Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
Maybe spatie cache key loads before your "cache bootstrapper" |
Beta Was this translation helpful? Give feedback.
-
I managed to write a bootstrapper and extend the PermissionRegistrar class. <?php
declare(strict_types=1);
namespace App\Tenancy\Bootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Spatie\Permission\PermissionRegistrar;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
class PermissionRegistrarBootstrapper implements TenancyBootstrapper
{
/** @var PermissionRegistrar */
protected $originalPermissionRegistrar;
/** @var Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function bootstrap(Tenant $tenant)
{
$this->originalPermissionRegistrar ??= $this->app[PermissionRegistrar::class];
$this->app->extend(
abstract: PermissionRegistrar::class,
closure: fn() => new PermissionRegistrar($this->app['cache']),
);
}
public function revert()
{
$this->app->extend(
abstract: PermissionRegistrar::class,
closure: fn() => $this->originalPermissionRegistrar,
);
$this->originalPermissionRegistrar = null;
}
} And add the bootstrapper in 'bootstrappers' => [
// ...
Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
App\Tenancy\Bootstrappers\PermissionRegistrarBootstrapper::class,
], |
Beta Was this translation helpful? Give feedback.
Maybe spatie cache key loads before your "cache bootstrapper"
laravel-permission/src/PermissionServiceProvider.php
Line 16 in 384e06f
laravel-permission/src/PermissionRegistrar.php
Line 82 in 384e06f