dev-master
9999999-devPermissions for Laravel 5.6
MIT
The Requires
- php ^7.1
- laravel/framework ^5.5
by Jurre
Permissions for Laravel 5.6
A very simple permission package for Laravel 5.6. Includes roles and permissions., (*1)
You can install the package via composer:, (*2)
``` bash composer require solarios/permission, (*3)
Because Laravel >= 5.5 uses auto-disover, the service provider will automatically register. If you want to include it manually, do so in the `config/app.php` file. ```php 'providers' => [ // ... Solarios\Permission\PermissionServiceProvider::class, ];
The packages comes with 2 traits:, (*4)
The hasPermissionTo()
method checks if the model has a permission. If the model also uses roles, it will also check the role for the permission., (*5)
$user->givePermissionTo('manage users'); $user->hasPermissionTo('manage users'); // Returns: true
Or when there is a role 'admin' with the 'manage users' permission:, (*6)
$user->giveRole('admin'); // The admin role has the 'manage users' permission. $role->hasPermissionTo('manage users'); // Returns: true
Remove a permission, (*7)
$user->revokePermissionTo('manage users');
Use this trait to give a model roles., (*8)
$user->giveRole('editor'); $user->hasRole('editor'); // Returns: true
Remove a role, (*9)
$user->revokeRole('editor');
Roles and permissions both have a polymorphic relation so we are not bound to one (user) model., (*10)
Permissions for Laravel 5.6
MIT