Download the PHP package zehirpx/laroles without Composer
On this page you can find all versions of the php package zehirpx/laroles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zehirpx/laroles
More information about zehirpx/laroles
Files in zehirpx/laroles
Package laroles
Short Description A light permission management for Laravel.
License MIT
Informations about the package laroles
la-roles
A light permission management for Laravel.
Requirements
- Laravel >= 5.0
Installation
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.
Quickstart
Create a role
You can create a role by using the create
method of the RoleRepository
:
Assign roles to a User
You can assign or re-assign roles for a user by using the updateUserRoles
method of the RoleRepository
:
Note: A user can be assigned to multiple roles.
Check permissions on a User
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.
Note: The
roleCan
method will checking on all the roles that assigned to the user.
Check permissions on a Role
You may also wish to check for the permissions on a Role
model by using the can
method of the model: