Skip to main content
Back to packages
178 GitHub stars

directorytree/authorization

View on GitHub

Description

Easy, native Laravel user authorization.

Authorization uses native Laravel relationships, so there's no need to learn a new API if you don't want to.

Due to Authorization's trait based implementation, all of Authorization's functionality can be overridden or extended with you own implementation.

Managing Roles & Permissions

Create a permission:

use DirectoryTree\Authorization\Permission;
 
$createUsers = Permission::create([
'name' => 'users.create',
'label' => 'Create Users',
]);

Create a role:

use DirectoryTree\Authorization\Role;
 
$admin = Role::create([
'name' => 'administrator',
'label' => 'Admin',
]);

Grant the permission to a role:

$admin->permissions()->save($createUsers);

Now assign the role to the user:

$user->roles()->save($admin);

Recent Courses on Laravel Daily

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

Roles and Permissions in Laravel 13

14 lessons
57 min

How to Structure Laravel 13 Projects

16 lessons
1 h 32 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.