solarios / permission
Permissions for Laravel 5.6
Requires
- php: ^7.1
- laravel/framework: ^5.5
This package is not auto-updated.
Last update: 2025-01-20 00:52:43 UTC
README
A very simple permission package for Laravel 5.6. Includes roles and permissions.
You can install the package via composer:
composer require solarios/permission
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.
'providers' => [ // ... Solarios\Permission\PermissionServiceProvider::class, ];
Usage
The packages comes with 2 traits:
- HasPermissions
- HasRoles
HasPermissions
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.
$user->givePermissionTo('manage users'); $user->hasPermissionTo('manage users'); // Returns: true
Or when there is a role 'admin' with the 'manage users' permission:
$user->giveRole('admin'); // The admin role has the 'manage users' permission. $role->hasPermissionTo('manage users'); // Returns: true
Remove a permission
$user->revokePermissionTo('manage users');
Hasroles
Use this trait to give a model roles.
$user->giveRole('editor'); $user->hasRole('editor'); // Returns: true
Remove a role
$user->revokeRole('editor');
Relations
Roles and permissions both have a polymorphic relation so we are not bound to one (user) model.