The DirectoryTree Authorization bundle by Steve Bauman is a straightforward, native function and permission administration system for Laravel.
If you happen to want a brilliant easy native feeling Laravel Authorization bundle, this one could tickle your fancyhttps://t.co/Xiu4Ty0IkR
— Steve (@ste_bau) April 23, 2024
It really works with Laravel’s Gate and authorization strategies out of the field, and provides the next light-weight API to handle roles and permissions:
use DirectoryTreeAuthorizationPermission;
use DirectoryTreeAuthorizationRole;
$createUsers = Permission::create([
'name' => 'users.create',
'label' => 'Create Users',
]);
$admin = Function::create([
'name' => 'administrator',
'label' => 'Admin',
]);
// Grant the permission to a task
$admin->permissions()->save($createUsers);
// Assign the function to a person
$person->roles()->save($admin);
// `can()` methodology utilization in PHP:
Auth::person()->can('customers.create');
// Utilizing Laravel's `Gate`:
Gate::permits('customers.create');
// Utilizing Laravel's `@can()` directive:
@can('customers.create')
<!-- This person can create different customers. -->
@endcan
The above code snippet would not comprise each methodology out there—see the readme for utilization particulars on managing roles and permissions with this bundle, which incorporates the next foremost options:
- Handle Person roles and Permissions
- Create user-specific permissions
- Checking permissions and roles
- Caching permissions by default
- Use with Laravel’s native Gate and authorization strategies.
- Permissions are registered in Laravel’s Gate by default
- Contains helpful permission and function middleware
To get began with this bundle, take a look at bundle on GitHub at directorytree/authorization.