roundly-consulting / teams-for-laravel
Associate users with teams, roles, permissions, and invitations in Laravel.
Package info
github.com/roundly-consulting/teams-for-laravel
pkg:composer/roundly-consulting/teams-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/contracts: ^12.0|^13.0
- roundly-consulting/addresses-for-laravel: ^1.0
- roundly-consulting/approvals-for-laravel: ^1.0
- roundly-consulting/connections-for-laravel: ^1.0
- roundly-consulting/contacts-for-laravel: ^1.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/options-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Teams for Laravel
Teams, roles, permissions and invitations for any Eloquent model. Members carry a role, roles carry permissions checked through Laravel's Gate, and teams issue expiring, email-targeted invites and handle join requests.
Installation
Requires PHP 8.4 and Laravel 12 or 13.
composer require roundly-consulting/teams-for-laravel php artisan vendor:publish --tag="options-migrations" php artisan vendor:publish --tag="contacts-migrations" php artisan vendor:publish --tag="addresses-migrations" php artisan vendor:publish --tag="connections-migrations" php artisan vendor:publish --tag="approvals-migrations" php artisan vendor:publish --tag="teams-migrations" php artisan migrate
Publish every tag: none of these packages auto-load their migrations, and the very first
Teams::create() needs the options table. If your users have UUID/ULID keys, set
TEAMS_KEY_TYPE before migrating.
Usage
Register your roles in a service provider's boot method and add HasTeams to your user:
use RoundlyConsulting\Teams\Facades\Teams; use RoundlyConsulting\Teams\Traits\HasTeams; Teams::roles()->register('owner', 'Owner', ['*']); Teams::roles()->register('editor', 'Editor', ['posts.edit', 'posts.publish']); Teams::roles()->register('member', 'Member', ['posts.view']); class User extends Authenticatable { use HasTeams; }
Then create a team, seat members and invite people:
use RoundlyConsulting\Teams\DataTransferObjects\CreateTeamData; use RoundlyConsulting\Teams\Facades\Teams; $team = Teams::create(new CreateTeamData(name: 'Acme', owner: $owner)); // owner joins as 'owner' Teams::for($team)->members()->add($alice, 'editor'); $invite = Teams::for($team)->invites()->create(role: 'member', email: 'jane@acme.test'); Teams::invites()->accept($invite->code, $jane, email: $jane->email); $alice->can('teams.posts.publish', $team); // true $jane->hasTeamRole($team, 'member'); // true $owner->can('teams.owner', $team); // true
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/teams-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). Please see License File for more information.