PHP Classes

How to use a PHP RBAC library to manage permissions of users and groups in a Laravel application using the package Laravel Teams Permissions: Manage user and group permissions in Laravel apps

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-12-02 (12 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
laravelteamspermissi 1.0MIT/X Consortium ...7User Management, Libraries, PHP 7
Description 

Authors

Alberto Rial Barreiro
Jacobo Cantorna Cigarrán


Contributor

This package can manage user and group permissions in Laravel applications.

It provides a Laravel service class that implements several services to manage permissions of application users and groups:

Currently, it can:

- Create database tables to store information for teams, permissions, roles, user, abilities, ability, groups, user, permission, invitations, team audit logs

- Support multi-tenant applications

- Manage Role-Based Access Control (RBAC) permissions

- Entity-specific abilities

- Global groups

- Audit logging

- REST API

Picture of Jacobo Cantorna Cigarrán
  Performance   Level  
Name: Jacobo Cantorna Cigarrán <contact>
Classes: 4 packages by
Country: Spain Spain
Age: 45
All time rank: Not yet ranked
Week rank: Not yet ranked
Innovation award
Innovation award
Nominee: 2x

Instructions

Documentation

Squareetlabs/LaravelTeamsPermissions

Latest Stable Version Total Downloads PHP Version Require License

A comprehensive Laravel package designed for advanced team-based permission management in multi-tenant applications based on [Jurager/Teams]. This package provides a flexible and powerful system for organizing users into teams, assigning granular permissions through roles and groups, and managing entity-specific access controls.

Core Functionality:

  • Team Management: Create and manage teams with owners and members. Each team operates as an independent workspace with its own set of roles, permissions, and members.
  • Role-Based Access Control (RBAC): Define custom roles for each team with specific permission sets. Roles can be assigned to users within a team, providing a flexible way to manage access levels. Team owners automatically have full access to all permissions.
  • Permission System: Implement fine-grained permissions using a code-based system (e.g., `posts.create`, `users.edit`). Permissions are global entities that can be assigned to roles and groups across multiple teams. Supports wildcard permissions for flexible access patterns.
  • Group Management: Organize users into groups within teams or globally. Groups can have their own permission sets, and permissions assigned to a group take precedence over individual user permissions within a team. This allows for efficient permission management when multiple users need the same access level.
  • Global Groups: Create groups without team association to grant users access across all teams with the group's permissions. Perfect for scenarios like support teams, administrators, or auditors who need consistent access across multiple teams without being individually added to each one.
  • Entity-Specific Abilities: Grant or deny permissions for specific model instances (e.g., allowing a user to edit a particular post but not others). This provides the most granular level of access control, enabling fine-tuned permissions for individual resources.
  • Multi-Tenant Support: Built from the ground up for multi-tenant applications where each team represents a tenant. Teams are completely isolated, ensuring data security and access control between different tenants.
  • Caching & Performance: Optional intelligent caching system to optimize permission checks, reducing database queries and improving application performance.
  • Audit Logging: Optional comprehensive audit trail that logs all team-related actions including role assignments, permission changes, and member additions/removals.
  • REST API: Optional complete REST API for team management, enabling frontend applications and third-party integrations to manage teams programmatically.
  • Laravel Integration: Seamlessly integrates with Laravel's built-in authorization system, including Policies, Blade directives, and middleware for route protection.

Key Features

  • ? Team Management: Create and manage teams with owners and members
  • ? Roles & Permissions: Flexible role system with granular permissions
  • ? Groups: Organize users into groups with shared permissions
  • ? Abilities: Entity-specific permissions for individual models
  • ? Smart Caching: Caching system to optimize permission checks
  • ? Audit Logging: Complete action logging for teams (optional)
  • ? REST API: Complete API for team management (optional)
  • ? Blade Directives: Blade directives for permission checks in views
  • ? Policies: Integration with Laravel's Policy system
  • ? Rate Limiting: Protection against invitation spam
  • ? Middleware: Middleware for route protection
  • ? Artisan Commands: CLI tools for management

Requirements

  • PHP >= 8.1
  • Laravel 8.x, 9.x, 10.x, 11.x or 12.x

Installation

1. Install the Package

composer require squareetlabs/laravel-teams-permissions

2. Publish Configuration and Migrations

php artisan vendor:publish --provider="Squareetlabs\LaravelTeamsPermissions\TeamsServiceProvider"

This will publish: - config/teams.php - Configuration file - Database migrations

3. Configure the User Model

Add the HasTeams trait to your User model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Squareetlabs\LaravelTeamsPermissions\Traits\HasTeams;

class User extends Model
{
    use HasTeams;
    
    // ... rest of your code
}

4. Run Migrations

> ?? IMPORTANT: Always do backups before running migrations.

php artisan migrate

> [!NOTE] > If you wish to use custom foreign keys and table names, modify config/teams.php before running migrations.

5. Optional Configuration

Enable Caching

To improve performance, enable caching in .env:

TEAMS_CACHE_ENABLED=true
TEAMS_CACHE_DRIVER=redis
TEAMS_CACHE_TTL=3600

Enable Audit Logging

To log all team actions:

TEAMS_AUDIT_ENABLED=true
TEAMS_AUDIT_LOG_CHANNEL=teams

> [!NOTE] > If you enable audit logging after running migrations, you'll need to publish and run the audit migration: > `bash > php artisan vendor:publish --tag=teams-migrations > php artisan migrate > `

Enable REST API

To expose a REST API for team management:

TEAMS_API_ENABLED=true

Configuration

The configuration file config/teams.php contains all options:

Custom Models

'models' => [
    'user' => App\Models\User::class,
    'team' => Squareetlabs\LaravelTeamsPermissions\Models\Team::class,
    // ... other models
],

Cache

'cache' => [
    'enabled' => env('TEAMS_CACHE_ENABLED', true),
    'driver' => env('TEAMS_CACHE_DRIVER', 'redis'),
    'ttl' => env('TEAMS_CACHE_TTL', 3600),
    'prefix' => 'teams_permissions',
    'tags' => true,
],

Audit

'audit' => [
    'enabled' => env('TEAMS_AUDIT_ENABLED', false),
    'log_channel' => env('TEAMS_AUDIT_LOG_CHANNEL', 'teams'),
    'events' => [
        'role_assigned',
        'permission_granted',
        'permission_revoked',
        'team_member_added',
        'team_member_removed',
    ],
],

See config/teams.php for all available options.

Basic Usage

Creating a Team

use Squareetlabs\LaravelTeamsPermissions\Models\Team;

$team = Team::create([
    'name' => 'My Team',
    'user_id' => auth()->id(),
]);

Adding Roles and Permissions

// Add role with permissions
$team->addRole('admin', [
    'posts.*',
    'users.*',
    'settings.edit',
], 'Administrator', 'Role with all permissions');

$team->addRole('editor', [
    'posts.view',
    'posts.create',
    'posts.edit',
], 'Editor', 'Can manage posts');

Adding Team Members

// Add user with a role
$team->addUser($user, 'editor');

// Update user's role
$team->updateUser($user, 'admin');

// Remove user
$team->deleteUser($user);

Checking Permissions

// Check if user has a permission
if ($user->hasTeamPermission($team, 'posts.create')) {
    // User can create posts
}

// Check if user has a role
if ($user->hasTeamRole($team, 'admin')) {
    // User is admin
}

// Check specific ability on an entity
if ($user->hasTeamAbility($team, 'edit', $post)) {
    // User can edit this specific post
}

Teams

Available Methods

// Access the team's owner
$team->owner

// Get all team users (excluding owner)
$team->users()

// Get all users including owner
$team->allUsers()

// Check if a user belongs to the team
$team->hasUser($user)

// Add user with a role (by ID or code)
$team->addUser($user, 'admin')

// Update user's role
$team->updateUser($user, 'editor')

// Remove user from team
$team->deleteUser($user)

// Invite user by email
$team->inviteUser('[email protected]', 'member')

// Accept invitation
$team->inviteAccept($invitation_id)

// Get all team abilities
$team->abilities()

// Get all team roles
$team->roles()

// Get user's role in the team
$team->userRole($user)

// Check if team has a role
$team->hasRole('admin') // or null to check if has any role

// Get role by ID or code
$team->getRole('admin')

// Add new role
$team->addRole($code, $permissions, $name, $description)

// Update role
$team->updateRole('admin', $newPermissions, $name, $description)

// Delete role
$team->deleteRole('admin')

// Get all groups
$team->groups()

// Get group by ID or code
$team->getGroup('moderators')

// Add new group
$team->addGroup($code, $permissions, $name)

// Update group
$team->updateGroup('moderators', $newPermissions, $name)

// Delete group
$team->deleteGroup('moderators')

// Check if team has user with email
$team->hasUserWithEmail('[email protected]')

// Check if user has permission in team
$team->userHasPermission($user, 'posts.create', $require = false)

// Get all invitations
$team->invitations()

Users

The HasTeams trait provides the following methods:

// Get teams the user belongs to
$user->teams

// Get teams the user owns
$user->ownedTeams

// Get all teams (owned and belongs to)
$user->allTeams()

// Check if user owns a team
$user->ownsTeam($team)

// Check if user belongs to a team
$user->belongsToTeam($team)

// Get user's role in a team
$user->teamRole($team)

// Check if user has a role (or roles) in a team
// $require = true: all roles are required
// $require = false: at least one of the roles
$user->hasTeamRole($team, 'admin', $require = false)
$user->hasTeamRole($team, ['admin', 'editor'], $require = false)

// Get all user's permissions for a team
// $scope: 'role', 'group', or null for all
$user->teamPermissions($team, $scope = null)

// Check if user has a permission (or permissions) in a team
// $require = true: all permissions are required
// $require = false: at least one of the permissions
// $scope: 'role', 'group', or null for all
$user->hasTeamPermission($team, 'posts.create', $require = false, $scope = null)
$user->hasTeamPermission($team, ['posts.create', 'posts.edit'], $require = false)

// Get user's abilities for a specific entity
$user->teamAbilities($team, $entity, $forbidden = false)

// Check if user has an ability on an entity
$user->hasTeamAbility($team, 'edit', $post)

// Allow ability for user on an entity
$user->allowTeamAbility($team, 'edit', $post)

// Forbid ability for user on an entity
$user->forbidTeamAbility($team, 'edit', $post)

// Delete ability
$user->deleteTeamAbility($team, 'edit', $post)

// Scope for eager loading permissions
User::withTeamPermissions()->get()

Roles & Permissions

Creating Roles with Permissions

$team->addRole('admin', [
    'posts.*',           // All post permissions
    'users.view',        // View users
    'users.create',      // Create users
    'users.edit',        // Edit users
    'users.delete',      // Delete users
    'settings.*',        // All settings permissions
], 'Administrator', 'Role with full access');

Wildcard Permissions

You can use wildcards for permissions:

  • `posts.*` - All permissions starting with `posts.`
  • `*` - All permissions (if enabled in config)

Checking Permissions

// Check simple permission
if ($user->hasTeamPermission($team, 'posts.create')) {
    // User can create posts
}

// Check multiple permissions (OR)
if ($user->hasTeamPermission($team, ['posts.create', 'posts.edit'], false)) {
    // User can create OR edit posts
}

// Check multiple permissions (AND)
if ($user->hasTeamPermission($team, ['posts.create', 'posts.edit'], true)) {
    // User can create AND edit posts
}

Wildcard Permissions

You can enable wildcard permissions in configuration:

'wildcards' => [
    'enabled' => true,
    'nodes' => [
        '*',
        '.',
        'all'
    ]
]

Users with these permissions will have full access to the team.

Abilities

Abilities allow specific permissions for individual entities.

Adding an Ability

// Allow user to edit a specific post
$user->allowTeamAbility($team, 'edit', $post);

// Forbid user to edit a specific post
$user->forbidTeamAbility($team, 'edit', $post);

Checking an Ability

if ($user->hasTeamAbility($team, 'edit', $post)) {
    // User can edit this specific post
}

Access Levels

Abilities use an access level system:

| Level | Value | Description | |-------|-------|-------------| | DEFAULT | 0 | No explicit permissions | | FORBIDDEN | 1 | Access denied | | ROLE_ALLOWED | 2 | Allowed by role | | ROLE_FORBIDDEN | 3 | Forbidden by role | | GROUP_ALLOWED | 4 | Allowed by group | | GROUP_FORBIDDEN | 5 | Forbidden by group | | USER_ALLOWED | 5 | Specifically allowed to user | | USER_FORBIDDEN | 6 | Specifically forbidden to user | | GLOBAL_ALLOWED | 6 | Global permissions |

Access is granted if the allowed level >= forbidden level.

Groups

Groups allow organizing users with shared permissions.

Creating and Managing Groups

// Add group
$team->addGroup('moderators', [
    'posts.moderate',
    'comments.moderate',
], 'Moderators');

// Update group
$team->updateGroup('moderators', [
    'posts.moderate',
    'comments.moderate',
    'users.moderate',
], 'Moderators');

// Delete group
$team->deleteGroup('moderators');

// Get group
$group = $team->getGroup('moderators');

// Add users to group
$group->users()->attach($user);
// or multiple users
$group->users()->attach([$user1->id, $user2->id]);

// Remove users from group
$group->users()->detach($user);

Global Groups

Groups without team_id are global and apply to all teams:

// Create global group (team_id = null)
$globalGroup = Group::create([
    'code' => 'support',
    'name' => 'Support Team',
    'team_id' => null,
]);

Middleware

The package provides middleware for route protection.

Configuration

Middleware is automatically registered as role, permission, and ability.

Usage in Routes

// Check role
Route::middleware(['role:admin,team_id'])->group(function () {
    Route::get('/admin', [AdminController::class, 'index']);
});

// Check permission
Route::middleware(['permission:posts.create,team_id'])->group(function () {
    Route::post('/posts', [PostController::class, 'store']);
});

// Check ability
Route::middleware(['ability:edit,App\Models\Post,post_id'])->group(function () {
    Route::put('/posts/{post_id}', [PostController::class, 'update']);
});

OR Operations

// User must have admin OR root
Route::middleware(['role:admin|root,team_id'])->group(function () {
    // ...
});

AND Operations

// User must have admin AND editor
Route::middleware(['role:admin|editor,team_id,require'])->group(function () {
    // ...
});

Blade Directives

The package includes Blade directives for permission checks in views:

{{-- Check role --}}
@teamRole($team, 'admin')
    <button>Admin Panel</button>
@endteamRole

{{-- Check permission --}}
@teamPermission($team, 'posts.create')
    <a href="{{ route('posts.create') }}">New Post</a>
@endteamPermission

{{-- Check ability --}}
@teamAbility($team, 'edit', $post)
    <button>Edit Post</button>
@endteamAbility

Policies

The package integrates with Laravel's Policy system.

Generate a Policy

php artisan teams:policy PostPolicy --model=Post

This generates a policy extending TeamPolicy:

namespace App\Policies;

use App\Models\Post;
use Squareetlabs\LaravelTeamsPermissions\Policies\TeamPolicy;

class PostPolicy extends TeamPolicy
{
    public function view(User $user, Post $post): bool
    {
        $team = $this->getTeamFromModel($post);
        return $this->checkTeamPermission($user, $team, 'posts.view');
    }

    public function update(User $user, Post $post): bool
    {
        $team = $this->getTeamFromModel($post);
        return $this->checkTeamAbility($user, $team, 'posts.update', $post);
    }
}

Using the Policy

// In a controller
if ($user->can('view', $post)) {
    // User can view the post
}

// In a view
@can('update', $post)
    <button>Edit</button>
@endcan

REST API

If you enable the REST API, you'll have access to complete endpoints for team management.

Enable API

TEAMS_API_ENABLED=true

Available Endpoints

GET    /api/teams                    - List teams
POST   /api/teams                    - Create team
GET    /api/teams/{team}             - View team
PUT    /api/teams/{team}             - Update team
DELETE /api/teams/{team}             - Delete team

GET    /api/teams/{team}/members     - List members
POST   /api/teams/{team}/members     - Add member
PUT    /api/teams/{team}/members/{user} - Update member role
DELETE /api/teams/{team}/members/{user} - Remove member

GET    /api/teams/{team}/roles       - List roles
POST   /api/teams/{team}/roles       - Create role
PUT    /api/teams/{team}/roles/{role} - Update role
DELETE /api/teams/{team}/roles/{role} - Delete role

GET    /api/teams/{team}/groups      - List groups
POST   /api/teams/{team}/groups      - Create group
PUT    /api/teams/{team}/groups/{group} - Update group
DELETE /api/teams/{team}/groups/{group} - Delete group

GET    /api/teams/{team}/permissions - List permissions

Authentication

The API requires Sanctum authentication:

// In your frontend application
axios.get('/api/teams', {
    headers: {
        'Authorization': 'Bearer ' + token
    }
});

Artisan Commands

The package includes several useful commands:

Team Management

# List all teams
php artisan teams:list

# View team details
php artisan teams:show {team}

# View team permissions
php artisan teams:permissions {team}

# Add member to team
php artisan teams:add-member {team} {user} {role}

Permission Management

# Sync permissions from configuration
php artisan teams:sync-permissions

# Export team permissions
php artisan teams:export-permissions {team} --format=json

# Import permissions to team
php artisan teams:import-permissions {team} --file=permissions.json

Utilities

# Clear permissions cache
php artisan teams:clear-cache

# Generate a policy
php artisan teams:policy PostPolicy --model=Post

Caching

The caching system significantly improves permission check performance.

Configuration

'cache' => [
    'enabled' => true,
    'driver' => 'redis',
    'ttl' => 3600, // 1 hour
    'prefix' => 'teams_permissions',
    'tags' => true,
],

Clear Cache

php artisan teams:clear-cache

Or programmatically:

use Squareetlabs\LaravelTeamsPermissions\Support\Services\PermissionCache;

$cache = new PermissionCache();
$cache->flush();

Audit Logging

The audit system logs all important team actions.

Enable Audit

TEAMS_AUDIT_ENABLED=true
TEAMS_AUDIT_LOG_CHANNEL=teams

Audited Events

  • `role_assigned` - Role assignment
  • `permission_granted` - Permission granted
  • `permission_revoked` - Permission revoked
  • `team_member_added` - Member added
  • `team_member_removed` - Member removed

Query Logs

use Squareetlabs\LaravelTeamsPermissions\Models\TeamAuditLog;

// Get logs for a team
$logs = TeamAuditLog::where('team_id', $team->id)->get();

// Get logs for a user
$logs = TeamAuditLog::where('user_id', $user->id)->get();

// Get logs for a specific action
$logs = TeamAuditLog::where('action', 'team_member_added')->get();

> [!NOTE] > If you enable audit logging after running migrations, you'll need to run: > `bash > php artisan vendor:publish --tag=teams-migrations > php artisan migrate > `

Events

The package fires events for important actions:

use Squareetlabs\LaravelTeamsPermissions\Events\TeamMemberAdded;
use Squareetlabs\LaravelTeamsPermissions\Events\TeamMemberRemoved;

Event::listen(TeamMemberAdded::class, function ($team, $user) {
    // Notify user they were added
});

Event::listen(TeamMemberRemoved::class, function ($team, $user) {
    // Notify user they were removed
});

Available Events

  • `TeamCreating` / `TeamCreated`
  • `TeamUpdating` / `TeamUpdated`
  • `TeamDeleted`
  • `TeamMemberAdding` / `TeamMemberAdded`
  • `TeamMemberRemoving` / `TeamMemberRemoved`
  • `TeamMemberUpdated`
  • `TeamMemberInviting` / `TeamMemberInvited`

Validation

The package includes validation rules:

use Squareetlabs\LaravelTeamsPermissions\Rules\ValidPermission;

$request->validate([
    'permission' => ['required', new ValidPermission()],
]);

Usage Examples

Blog System with Teams

// Create team
$team = Team::create([
    'name' => 'Blog Team',
    'user_id' => auth()->id(),
]);

// Add roles
$team->addRole('editor', ['posts.*', 'comments.moderate'], 'Editor');
$team->addRole('author', ['posts.create', 'posts.edit'], 'Author');
$team->addRole('viewer', ['posts.view'], 'Viewer');

// In a controller
public function store(Request $request)
{
    $team = Team::find($request->team_id);
    
    if (!auth()->user()->hasTeamPermission($team, 'posts.create')) {
        abort(403);
    }
    
    // Create post...
}

Multi-tenant SaaS Application

// Each client has their own team
$clientTeam = Team::create([
    'name' => $client->name,
    'user_id' => $client->owner_id,
]);

// Client-specific roles
$clientTeam->addRole('admin', ['*'], 'Administrator');
$clientTeam->addRole('user', ['dashboard.view', 'reports.view'], 'User');

// Check access in middleware
Route::middleware(['permission:dashboard.view,team_id'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});

Testing

The package includes factories and seeders for testing:

use Squareetlabs\LaravelTeamsPermissions\Database\Factories\TeamFactory;

$team = TeamFactory::new()
    ->withRoles()
    ->withGroups()
    ->create();

Troubleshooting

Error: "Model class for key user not found"

Make sure your User model is configured in config/teams.php:

'models' => [
    'user' => App\Models\User::class,
],

Error: "AuditTableMissingException"

If you enable audit logging after running migrations:

php artisan vendor:publish --tag=teams-migrations
php artisan migrate

Or disable audit logging in config/teams.php:

'audit' => [
    'enabled' => false,
],

Cache Not Updating

Clear cache manually:

php artisan teams:clear-cache

API Documentation

Classes and Methods

HasTeams Trait

Methods available on User model:

  • `ownsTeam(Team $team): bool` - Check if user owns the team
  • `allTeams(): Collection` - Get all teams (owned and belongs to)
  • `ownedTeams(): HasMany` - Get teams user owns
  • `teams(): BelongsToMany` - Get teams user belongs to
  • `belongsToTeam(Team $team): bool` - Check if user belongs to team
  • `teamRole(Team $team): ?Role` - Get user's role in team
  • `hasTeamRole(Team $team, string|array $roles, bool $require = false): bool` - Check if user has role(s)
  • `teamPermissions(Team $team, ?string $scope = null): array` - Get user's permissions for team
  • `hasTeamPermission(Team $team, string|array $permissions, bool $require = false, ?string $scope = null): bool` - Check if user has permission(s)
  • `teamAbilities(Team $team, Model $entity, bool $forbidden = false): Collection` - Get user's abilities for entity
  • `hasTeamAbility(Team $team, string $permission, Model $action_entity): bool` - Check if user has ability
  • `allowTeamAbility(Team $team, string $permission, Model $action_entity, ?Model $target_entity = null): void` - Allow ability
  • `forbidTeamAbility(Team $team, string $permission, Model $action_entity, ?Model $target_entity = null): void` - Forbid ability
  • `deleteTeamAbility(Team $team, string $permission, Model $action_entity, ?Model $target_entity = null): void` - Delete ability
  • `scopeWithTeamPermissions($query)` - Eager load team permissions

HasMembers Trait

Methods available on Team model:

  • `owner(): BelongsTo` - Get team owner
  • `users(): BelongsToMany` - Get team members
  • `abilities(): HasMany` - Get team abilities
  • `roles(): HasMany` - Get team roles
  • `groups(): HasMany` - Get team groups
  • `invitations(): HasMany` - Get pending invitations
  • `allUsers(): Collection` - Get all users including owner
  • `hasUser(User $user): bool` - Check if user is member
  • `addUser(User $user, string $role_keyword): void` - Add user to team
  • `updateUser(User $user, string $role_keyword): void` - Update user's role
  • `deleteUser(User $user): void` - Remove user from team
  • `inviteUser(string $email, int|string $keyword): void` - Invite user by email
  • `inviteAccept(int $invitation_id): void` - Accept invitation
  • `hasUserWithEmail(string $email): bool` - Check if team has user with email
  • `userRole(User $user): ?Role` - Get user's role in team
  • `userHasPermission(User $user, string|array $permissions, bool $require = false): bool` - Check if user has permission
  • `hasRole(int|string|null $keyword = null): bool` - Check if team has role
  • `getRole(int|string $keyword): ?Role` - Get role by ID or code
  • `addRole(string $code, array $permissions, ?string $name = null, ?string $description = null): Role` - Add role
  • `updateRole(int|string $keyword, array $permissions, ?string $name = null, ?string $description = null): Role` - Update role
  • `deleteRole(int|string $keyword): bool` - Delete role
  • `hasGroup(int|string|null $keyword = null): bool` - Check if team has group
  • `getGroup(int|string $keyword): ?Group` - Get group by ID or code
  • `addGroup(string $code, array $permissions = [], ?string $name = null): Group` - Add group
  • `updateGroup(int|string $keyword, array $permissions = [], ?string $name = null): Group` - Update group
  • `deleteGroup(int|string $keyword): bool` - Delete group
  • `purge(): void` - Delete team and all relations
  • `getPermissionIds(array $codes): array` - Get permission IDs for codes

PermissionCache Service

  • `remember(string $key, callable $callback, ?int $ttl = null): mixed` - Cache a value
  • `flush(): void` - Flush all cache
  • `forget(string $key): void` - Forget specific key
  • `get(string $key, mixed $default = null): mixed` - Get cached value

AuditService Service

  • `log(string $action, mixed $team, mixed $user, mixed $subject = null, ?array $oldValues = null, ?array $newValues = null): void` - Log audit event
  • `logRoleAssigned(mixed $team, mixed $user, mixed $role): void` - Log role assignment
  • `logPermissionGranted(mixed $team, mixed $user, string $permission): void` - Log permission granted
  • `logPermissionRevoked(mixed $team, mixed $user, string $permission): void` - Log permission revoked
  • `logTeamMemberAdded(mixed $team, mixed $user, mixed $member, mixed $role): void` - Log member added
  • `logTeamMemberRemoved(mixed $team, mixed $user, mixed $member): void` - Log member removed

TeamPolicy Base Class

  • `checkTeamPermission(Model $user, Model $team, string $permission): bool` - Check team permission
  • `checkTeamAbility(Model $user, Model $team, string $ability, Model $model): bool` - Check team ability
  • `checkTeamRole(Model $user, Model $team, string|array $roles): bool` - Check team role
  • `getTeamFromModel(Model $model): ?Model` - Get team from model

Contributing

Contributions are welcome. Please:

  1. Fork the project
  2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
  3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
  4. Push to the branch (`git push origin feature/AmazingFeature`)
  5. Open a Pull Request

Changelog

See CHANGELOG.md for the full list of changes.

License

This package is open-sourced software licensed under the MIT license.

Support

For support, please open an issue on GitHub.

Authors


  Files folder image Files (101)  
File Role Description
Files folder imageconfig (1 file)
Files folder imagedatabase (3 directories)
Files folder imageresources (1 directory)
Files folder imageroutes (2 files)
Files folder imagesrc (1 file, 12 directories)
Files folder imagestubs (1 directory)
Files folder imagetests (2 files, 4 directories)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file pint.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (101)  /  config  
File Role Description
  Plain text file teams.php Class Class source

  Files folder image Files (101)  /  database  
File Role Description
Files folder imagefactories (1 file)
Files folder imagemigrations (13 files)
Files folder imageseeders (1 file)

  Files folder image Files (101)  /  database  /  factories  
File Role Description
  Plain text file TeamFactory.php Class Class source

  Files folder image Files (101)  /  database  /  migrations  
File Role Description
  Plain text file add_performance_indexes.php Class Class source
  Plain text file create_abilities_table.php Class Class source
  Plain text file create_entity_ability_table.php Class Class source
  Plain text file create_entity_permission_table.php Class Class source
  Plain text file create_groups_table.php Class Class source
  Plain text file create_group_user_table.php Class Class source
  Plain text file create_invitations_table.php Class Class source
  Plain text file create_permissions_table.php Class Class source
  Plain text file create_roles_table.php Class Class source
  Plain text file create_teams_table.php Class Class source
  Plain text file create_team_audit_logs_table.php Class Class source
  Plain text file create_team_user_table.php Class Class source
  Plain text file remove_team_id_fro...rmissions_table.php Class Class source

  Files folder image Files (101)  /  database  /  seeders  
File Role Description
  Plain text file TeamsSeeder.php Class Class source

  Files folder image Files (101)  /  resources  
File Role Description
Files folder imageviews (1 directory)

  Files folder image Files (101)  /  resources  /  views  
File Role Description
Files folder imageemails (1 file)

  Files folder image Files (101)  /  resources  /  views  /  emails  
File Role Description
  Accessible without login Plain text file invitation.blade.php Aux. Configuration script

  Files folder image Files (101)  /  routes  
File Role Description
  Plain text file api.php Class Class source
  Plain text file web.php Class Class source

  Files folder image Files (101)  /  src  
File Role Description
Files folder imageConsole (10 files)
Files folder imageEnums (1 file)
Files folder imageEvents (13 files)
Files folder imageExceptions (1 file)
Files folder imageHttp (1 directory)
Files folder imageMail (1 file)
Files folder imageMiddleware (4 files)
Files folder imageModels (9 files)
Files folder imagePolicies (1 file)
Files folder imageRules (2 files)
Files folder imageSupport (2 directories)
Files folder imageTraits (2 files)
  Plain text file TeamsServiceProvider.php Class Class source

  Files folder image Files (101)  /  src  /  Console  
File Role Description
  Plain text file InstallCommand.php Class Class source
  Plain text file MakePolicyCommand.php Class Class source
  Plain text file TeamsAddMemberCommand.php Class Class source
  Plain text file TeamsClearCacheCommand.php Class Class source
  Plain text file TeamsExportPermissionsCommand.php Class Class source
  Plain text file TeamsImportPermissionsCommand.php Class Class source
  Plain text file TeamsListCommand.php Class Class source
  Plain text file TeamsPermissionsCommand.php Class Class source
  Plain text file TeamsShowCommand.php Class Class source
  Plain text file TeamsSyncPermissionsCommand.php Class Class source

  Files folder image Files (101)  /  src  /  Enums  
File Role Description
  Accessible without login Plain text file AccessLevel.php Aux. Configuration script

  Files folder image Files (101)  /  src  /  Events  
File Role Description
  Plain text file TeamCreated.php Class Class source
  Plain text file TeamCreating.php Class Class source
  Plain text file TeamDeleted.php Class Class source
  Plain text file TeamEvent.php Class Class source
  Plain text file TeamMemberAdded.php Class Class source
  Plain text file TeamMemberAdding.php Class Class source
  Plain text file TeamMemberInvited.php Class Class source
  Plain text file TeamMemberInviting.php Class Class source
  Plain text file TeamMemberRemoved.php Class Class source
  Plain text file TeamMemberRemoving.php Class Class source
  Plain text file TeamMemberUpdated.php Class Class source
  Plain text file TeamUpdated.php Class Class source
  Plain text file TeamUpdating.php Class Class source

  Files folder image Files (101)  /  src  /  Exceptions  
File Role Description
  Plain text file AuditTableMissingException.php Class Class source

  Files folder image Files (101)  /  src  /  Http  
File Role Description
Files folder imageControllers (4 files)

  Files folder image Files (101)  /  src  /  Http  /  Controllers  
File Role Description
  Plain text file RoleController.php Class Class source
  Plain text file TeamController.php Class Class source
  Plain text file TeamGroupController.php Class Class source
  Plain text file TeamMemberController.php Class Class source

  Files folder image Files (101)  /  src  /  Mail  
File Role Description
  Plain text file Invitation.php Class Class source

  Files folder image Files (101)  /  src  /  Middleware  
File Role Description
  Plain text file Ability.php Class Class source
  Plain text file Permission.php Class Class source
  Plain text file Role.php Class Class source
  Plain text file Teams.php Class Class source

  Files folder image Files (101)  /  src  /  Models  
File Role Description
  Plain text file Ability.php Class Class source
  Plain text file Group.php Class Class source
  Plain text file Invitation.php Class Class source
  Plain text file Membership.php Class Class source
  Plain text file Owner.php Class Class source
  Plain text file Permission.php Class Class source
  Plain text file Role.php Class Class source
  Plain text file Team.php Class Class source
  Plain text file TeamAuditLog.php Class Class source

  Files folder image Files (101)  /  src  /  Policies  
File Role Description
  Plain text file TeamPolicy.php Class Class source

  Files folder image Files (101)  /  src  /  Rules  
File Role Description
  Plain text file Role.php Class Class source
  Plain text file ValidPermission.php Class Class source

  Files folder image Files (101)  /  src  /  Support  
File Role Description
Files folder imageFacades (1 file)
Files folder imageServices (3 files)

  Files folder image Files (101)  /  src  /  Support  /  Facades  
File Role Description
  Plain text file Teams.php Class Class source

  Files folder image Files (101)  /  src  /  Support  /  Services  
File Role Description
  Plain text file AuditService.php Class Class source
  Plain text file PermissionCache.php Class Class source
  Plain text file TeamsService.php Class Class source

  Files folder image Files (101)  /  src  /  Traits  
File Role Description
  Plain text file HasMembers.php Class Class source
  Plain text file HasTeams.php Class Class source

  Files folder image Files (101)  /  stubs  
File Role Description
Files folder imageapp (2 directories)

  Files folder image Files (101)  /  stubs  /  app  
File Role Description
Files folder imageControllers (1 file)
Files folder imagePolicies (1 file)

  Files folder image Files (101)  /  stubs  /  app  /  Controllers  
File Role Description
  Plain text file InviteController.php Class Class source

  Files folder image Files (101)  /  stubs  /  app  /  Policies  
File Role Description
  Plain text file TeamPolicy.php Class Class source

  Files folder image Files (101)  /  tests  
File Role Description
Files folder imagedatabase (1 directory)
Files folder imageFeature (2 files, 1 directory)
Files folder imageModels (1 file)
Files folder imageUnit (3 directories)
  Plain text file Pest.php Class Class source
  Plain text file TestCase.php Class Class source

  Files folder image Files (101)  /  tests  /  database  
File Role Description
Files folder imagefactories (1 file)

  Files folder image Files (101)  /  tests  /  database  /  factories  
File Role Description
  Plain text file UserFactory.php Class Class source

  Files folder image Files (101)  /  tests  /  Feature  
File Role Description
Files folder imageMiddleware (3 files)
  Plain text file CacheTest.php Class Class source
  Plain text file PermissionCheckingTest.php Class Class source

  Files folder image Files (101)  /  tests  /  Feature  /  Middleware  
File Role Description
  Plain text file AbilityMiddlewareTest.php Class Class source
  Plain text file PermissionMiddlewareTest.php Class Class source
  Plain text file RoleMiddlewareTest.php Class Class source

  Files folder image Files (101)  /  tests  /  Models  
File Role Description
  Plain text file User.php Class Class source

  Files folder image Files (101)  /  tests  /  Unit  
File Role Description
Files folder imageModels (7 files)
Files folder imageServices (1 file)
Files folder imageTraits (2 files)

  Files folder image Files (101)  /  tests  /  Unit  /  Models  
File Role Description
  Plain text file AbilityTest.php Class Class source
  Plain text file GroupTest.php Class Class source
  Plain text file InvitationTest.php Class Class source
  Plain text file MembershipTest.php Class Class source
  Plain text file PermissionTest.php Class Class source
  Plain text file RoleTest.php Class Class source
  Plain text file TeamTest.php Class Class source

  Files folder image Files (101)  /  tests  /  Unit  /  Services  
File Role Description
  Plain text file PermissionCacheTest.php Class Class source

  Files folder image Files (101)  /  tests  /  Unit  /  Traits  
File Role Description
  Plain text file HasMembersTest.php Class Class source
  Plain text file HasTeamsTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0