DirectoryTree Authorization is a Native Role and Permission Management Package for Laravel

The DirectoryTree Authorization package by Steve Bauman is an easy, native role and permission management system for Laravel.

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

It works with Laravel's Gate and authorization methods out of the box, and offers the following lightweight API to manage roles and permissions:

use DirectoryTree\Authorization\Permission;
use DirectoryTree\Authorization\Role;

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

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

// Grant the permission to a role
$admin->permissions()->save($createUsers);

// Assign the role to a user
$user->roles()->save($admin);

// `can()` method usage in PHP:
Auth::user()->can('users.create');

// Using Laravel's `Gate`:
Gate::allows('users.create');

// Using Laravel's `@can()` directive:
@can('users.create')
    <!-- This user can create other users. -->
@endcan

The above code snippet doesn't contain every method available—see the readme for usage details on managing roles and permissions with this package, which includes the following main features:

To get started with this package, check out package on GitHub at directorytree/authorization.


The post DirectoryTree Authorization is a Native Role and Permission Management Package for Laravel appeared first on Laravel News.

Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.