malico / teams
Team management functionality for Laravel applications.
Requires
- php: ^8.2.0
- illuminate/console: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- symfony/console: ^7.0
Requires (Dev)
- inertiajs/inertia-laravel: ^2.0
- laravel/pint: ^1.24
- laravel/sanctum: ^4.0
- livewire/livewire: ^3.3
- livewire/volt: ^1.0
- mockery/mockery: ^1.0
- orchestra/testbench: ^9.0|^10.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2025-08-29 19:44:02 UTC
README
A comprehensive team management package for Laravel applications that provides robust multi-tenant functionality with support for team creation, member management, invitations, and role-based permissions.
Features
- Team Management: Complete team creation, updating, and deletion functionality
- Member Management: Add, remove, and manage team members with role-based access control
- Team Invitations: Email-based invitation system with acceptance and decline workflows
- Role & Permission System: Flexible role definitions with granular permission control
- Multi-Stack Support: Compatible with both Livewire and Inertia.js implementations
- Event-Driven Architecture: Comprehensive event system for custom business logic integration
- Personal Teams: Automatic personal team creation for new users
- Authorization Policies: Built-in policy classes for secure team operations
- Testing Support: Full Pest testing framework integration with comprehensive test coverage
Requirements
- PHP 8.1 or higher
- Laravel 11.0 or higher
Installation
Install the package via Composer:
composer require malico/teams
Run the installation command to publish migrations, models, and configuration files:
php artisan teams:install
The installation process will:
- Publish and run database migrations
- Publish configuration files
- Create necessary stub files for your chosen stack (Livewire or Inertia.js)
- Set up authentication overrides with team invitation support
Configuration
User Model Setup
Add the HasTeams
trait to your User model:
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Malico\Teams\HasTeams; class User extends Authenticatable { use HasTeams; // Your existing model code... }
Team Roles Configuration
Define team roles in your application's service provider:
use Malico\Teams\Teams; public function boot(): void { Teams::role('owner', 'Owner', [ 'team:read', 'team:update', 'team:delete', 'team:invite-members', 'team:remove-members', ])->description('Team owner with full administrative access'); Teams::role('admin', 'Administrator', [ 'team:read', 'team:update', 'team:invite-members', 'team:remove-members', ])->description('Team administrator with management privileges'); Teams::role('member', 'Member', [ 'team:read', ])->description('Standard team member with read access'); }
Usage
Creating Teams
use App\Actions\Teams\CreateTeam; $team = app(CreateTeam::class)->create($user, [ 'name' => 'Development Team', 'description' => 'Main development team for the project', ]);
Managing Team Members
use App\Actions\Teams\InviteTeamMember; use App\Actions\Teams\AcceptTeamInvitation; use App\Actions\Teams\DeclineTeamInvitation; // Invite a team member app(InviteTeamMember::class)->invite($user, $team, 'developer@example.com', 'admin'); // Accept an invitation app(AcceptTeamInvitation::class)->accept($user, $teamInvitation); // Decline an invitation app(DeclineTeamInvitation::class)->decline($teamInvitation);
Checking Team Permissions
// Check if user belongs to a team if ($user->belongsToTeam($team)) { // User is a team member } // Check user's role on a team if ($user->hasTeamRole($team, 'admin')) { // User is an admin on this team } // Check specific permissions if ($user->hasTeamPermission($team, 'team:update')) { // User can update this team }
Working with Current Team
// Get user's current team $currentTeam = $user->currentTeam; // Switch to a different team $user->switchTeam($team); // Get all user's teams $teams = $user->allTeams(); // Get teams where user owns $ownedTeams = $user->ownedTeams; // Get teams where user is a member $memberTeams = $user->teams;
Frontend Integration
This package supports both Livewire and Inertia.js stacks. The installation command will scaffold the appropriate components based on your selection.
Livewire Stack
After installation, you'll have Livewire components for:
- Team creation and management
- Member invitation and management
- Team switching interface
- Invitation acceptance/decline pages
Inertia.js Stack (coming soon)
After installation, you'll have Vue.js components and controllers for:
- Team management interfaces
- Member management
- Invitation handling
- Team switching functionality
Events
The package dispatches several events that you can listen to:
TeamCreated
: Fired when a team is createdTeamUpdated
: Fired when a team is updatedTeamDeleted
: Fired when a team is deletedTeamMemberAdded
: Fired when a member is added to a teamTeamMemberRemoved
: Fired when a member is removed from a teamTeamInvitationSent
: Fired when an invitation is sentTeamInvitationAccepted
: Fired when an invitation is acceptedTeamInvitationDeclined
: Fired when an invitation is declined
Testing
The package includes comprehensive test coverage using the Pest testing framework. You can run the tests using:
composer test
Authorization
The package includes authorization policies for secure team operations:
TeamPolicy
: Controls team-level operations
Contributing
Contributions are welcome. Please ensure that your code follows Laravel conventions and includes appropriate test coverage.
- Fork the repository
- Create a feature branch
- Write tests for your changes
- Ensure all tests pass
- Submit a pull request
Security
If you discover any security-related issues, please email the maintainer instead of using the issue tracker.
Credits
This package was extracted and enhanced from Laravel Jetstream's team functionality to provide a standalone, framework-agnostic solution for team management in Laravel applications.