| Package Data | |
|---|---|
| Maintainer Username: | zehirpx |
| Package Create Date: | 2016-10-26 |
| Package Last Update: | 2016-12-01 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-27 03:06:06 |
| Package Statistics | |
|---|---|
| Total Downloads: | 22 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 0 |
| Total Watchers: | 1 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
A light permission management for Laravel.
To get started, install the package via the Composer package manager:
composer require zehirpx/laroles
Next, register the service provider in the providers array of your config/app.php:
zehirpx\Laroles\LarolesServiceProvider::class,
Now, publish and migrate the migrations:
php artisan vendor:publish
php artisan migrate
After running the commands, addd the zehirpx\Laroles\HasRoles trait to your App\User model.
The trait will provide a few method to your model which allow you inspect the roles and permissions of the user.
<?php
namespace App;
use zehirpx\Laroles\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasRoles;
}
You can create a role by using the create method of the RoleRepository:
$roles = new zehirpx\Laroles\RoleRepository;
$roles->create('customer-support', 'Customer Support', [
'create-servers', 'update-servers']);
You can assign or re-assign roles for a user by using the updateUserRoles method of the RoleRepository:
$roles->updateUserRoles($user, ['customer-support']);
Note: A user can be assigned to multiple roles.
Since we have used the HasRoles trait to the App\User model, so we can use the rolesCan method to check
if the user's roles has the given permission.
$user->rolesCan('update-servers'); // true
$user->rolesCan('delete-servers'); // false
Note: The
roleCanmethod will checking on all the roles that assigned to the user.
You may also wish to check for the permissions on a Role model by using the can method of the model:
$role->can('create-servers'); // true
$role->can('delete-servers'); // false