Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with spatie/multi-tenancy #138

Open
scotchdesign opened this issue Oct 20, 2022 · 0 comments
Open

Integration with spatie/multi-tenancy #138

scotchdesign opened this issue Oct 20, 2022 · 0 comments

Comments

@scotchdesign
Copy link

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

'switch_tenant_tasks' => [
        ...
        \App\Tasks\SwitchTenantPermissionCacheTask::class,
       ...
    ],

App\Tasks\SwitchTenantPermissionCacheTask.php

<?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();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant