You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To integrate with spatie/multi-tenancy you need to reset the permission cache when the current tenant is changed. It would have been easier to add a suffix to the $cacheKey variable, however it's protected so doesn't seem to be able to be modified. Below is my work-around.
<?php
namespace App\Tasks;
use Spatie\Multitenancy\Models\Tenant;
use Spatie\Multitenancy\Tasks\SwitchTenantTask;
class SwitchTenantPermissionCacheTask implements SwitchTenantTask {
public function __construct() {
app(\Maklad\Permission\PermissionRegistrar::class)->forgetCachedPermissions();
app(\Maklad\Permission\PermissionRegistrar::class)->registerPermissions();
}
public function makeCurrent(Tenant $tenant): void {
app(\Maklad\Permission\PermissionRegistrar::class)->forgetCachedPermissions();
app(\Maklad\Permission\PermissionRegistrar::class)->registerPermissions();
}
public function forgetCurrent(): void {
app(\Maklad\Permission\PermissionRegistrar::class)->forgetCachedPermissions();
app(\Maklad\Permission\PermissionRegistrar::class)->registerPermissions();
}
}
The text was updated successfully, but these errors were encountered:
To integrate with spatie/multi-tenancy you need to reset the permission cache when the current tenant is changed. It would have been easier to add a suffix to the $cacheKey variable, however it's protected so doesn't seem to be able to be modified. Below is my work-around.
app/config/multitenancy.php
App\Tasks\SwitchTenantPermissionCacheTask.php
The text was updated successfully, but these errors were encountered: