Skip to content
Nav

Reference

composer require langsys/laravel-access-guard
Packagist version Monthly downloads License PHP 8.2+ Laravel 10 / 11 / 12

The role → permission map is cached (config cache.store / expiration_time) and flushed automatically on grant/revoke and any role/permission save or delete. Flush manually with php artisan access-guard:cache-reset.

Terminal window
php artisan access-guard:create-permission view_projects "View projects"
php artisan access-guard:create-role project_admin "Project Admin" --permissions=view_projects,edit_projects
php artisan access-guard:show # roles and the permissions they grant
php artisan access-guard:cache-reset

Anywhere a permission or role name is accepted you can pass a string or a backed enum:

enum Ability: string { case ViewProjects = 'view_projects'; }
$role->grantPermissions([Ability::ViewProjects]);
AccessGuard::allows(Ability::ViewProjects, $project);

Set events_enabled => true to fire RoleAssignedToModel, RoleRemovedFromModel, PermissionAssignedToRole, and PermissionRemovedFromRole — useful for audit logging.

Terminal window
composer install
composer test
Feedback