jurager / teams
Laravel package to manage team functionality and operate with user permissions.
Fund package maintenance!
Requires
- php: ^8.3
- illuminate/auth: ^10.30|^11.0|^12.0|^13.0
- illuminate/bus: ^10.30|^11.0|^12.0|^13.0
- illuminate/database: ^10.30|^11.0|^12.0|^13.0
- illuminate/http: ^10.30|^11.0|^12.0|^13.0
- illuminate/mail: ^10.30|^11.0|^12.0|^13.0
- illuminate/queue: ^10.30|^11.0|^12.0|^13.0
- illuminate/routing: ^10.30|^11.0|^12.0|^13.0
- illuminate/support: ^10.30|^11.0|^12.0|^13.0
- illuminate/validation: ^10.30|^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- pestphp/pest: ^2.34|^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Laravel package for managing teams and user permissions, supporting multi-tenant dynamic roles, role groups, and team-specific permissions.
Users can be organized into groups within teams, each with custom permissions and abilities. Group permissions add to the permissions of the member's role. For a specific record, the user's own rules are checked first, then their groups' rules, then their role's.
Additionally, users can be added to a global group to grant them access across all teams with the group's permissions. This feature is ideal for scenarios like providing support across multiple teams without the need to add users to each team individually.
Features
- Team-scoped roles and permissions with a fluent API.
- Works with Laravel's Gate:
$user->can(),@can, and thecanmiddleware. - Inspect access decisions with Laravel's authorization responses.
- String-backed enums for role, group, and permission codes.
- Hierarchical wildcard permissions (
articles.*). - Team groups that extend role permissions.
- Record-level allow and forbid rules for members, roles, and groups.
- Expiring record rules, checked at authorization time.
- Query users by team-wide permission.
- Query record rules with their permissions and recipients.
- Global groups for cross-team access.
- Ownership transfer.
- Email invitations.
- Fast permission checks on lists of records.
- Team, membership, and access change events.
- Model factories for your tests.
Requirements
- PHP 8.3+
- Laravel 10.30+, 11, 12, or 13
Installation
composer require jurager/teams php artisan vendor:publish --tag=teams-migrations php artisan migrate
Add Jurager\Teams\Traits\HasTeams to your User model:
use Jurager\Teams\Traits\HasTeams; class User extends Authenticatable { use HasTeams; }
Usage
$team = $owner->teams()->create(['name' => 'Acme']); $team->roles()->create(['code' => 'member'])->grant('articles.view'); $team->groups()->create(['code' => 'editors'])->grant('articles.*'); $team->add($user)->as('member'); $team->group('editors')->add($user); $team->member($user)->forbid('articles.delete')->on($article); $user->can('articles.edit', $article); // true $user->can('articles.delete', $article); // false
See the documentation for groups, route protection, invitations, and configuration.
Upgrading
Upgrading from 3.x? See the upgrade guide.
Development
composer install
composer test
composer format:test
License
This package is open-sourced software licensed under the MIT license.