Version 3 with Tenancy + Spatie's Permission package

Is it possible to have a Tenancy and each tenant have their own "Roles & Permissions"? I already implemented the tenancy part but currently I have an issue with the "unique" index of the tables related to the Roles and Permissions. What I'm trying to achieve is each tenant must have their own Roles and Permissions.
2 Replies
Meymink
Meymink13mo ago
https://spatie.be/docs/laravel-permission/v6/basic-usage/teams-permissions When creating a role you can pass the team_id as an optional parameter
// with null team_id it creates a global role; global roles can be assigned to any team and they are unique
Role::create(['name' => 'writer', 'team_id' => null]);

// creates a role with team_id = 1; team roles can have the same name on different teams
Role::create(['name' => 'reader', 'team_id' => 1]);

// creating a role without team_id makes the role take the default global team_id
Role::create(['name' => 'reviewer']);
// with null team_id it creates a global role; global roles can be assigned to any team and they are unique
Role::create(['name' => 'writer', 'team_id' => null]);

// creates a role with team_id = 1; team roles can have the same name on different teams
Role::create(['name' => 'reader', 'team_id' => 1]);

// creating a role without team_id makes the role take the default global team_id
Role::create(['name' => 'reviewer']);
The second option is what you are looking for as its a role created for the specified team (id.) Hence why it can have the same name on different teams because different teams can have a role with a name that some other teams may have already used.
Michael Mamaclay
Michael MamaclayOP13mo ago
Thank you @๖ۣۜζ͜͡Redicated
Want results from more Discord servers?
Add your server