Configuration
Enable Teams Feature
Open your
config/permission.php file and enable the teams feature:config/permission.php
This must be set to
true before running migrations. If you’ve already run migrations, you’ll need to create a new migration to add the team foreign key column.Configure Team Foreign Key
The default team foreign key column name is
team_id. You can customize this:config/permission.php
Custom Team Resolver
The package uses a team resolver to determine which team context to use for permissions.Default Team Resolver
The default implementation is simple:Creating a Custom Resolver
Create your own resolver to automatically detect the team from the authenticated user:app/Services/CustomTeamResolver.php
config/permission.php:
config/permission.php
Usage
Setting the Team Context
Use the helper function or facade to set the current team:Getting the Current Team
Creating Team-Scoped Roles
When teams are enabled, roles automatically include the team context:Global Roles
Roles withnull team_id are available to all teams:
Assigning Team-Scoped Roles
Team-Scoped Permissions
Middleware Example
Automatically set the team context for each request:app/Http/Middleware/SetPermissionsTeamId.php
app/Http/Kernel.php:
Important Considerations
Team Switching
When users switch teams, update the context:Querying Roles by Team
ThefindByName and findById methods respect the team context: