Download the PHP package dangkien/roleper without Composer
On this page you can find all versions of the php package dangkien/roleper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dangkien/roleper
More information about dangkien/roleper
Files in dangkien/roleper
Package roleper
Short Description This package provides a flexible way to add Role-based Permissions to Laravel
License MIT
Informations about the package roleper
RolePermission
Role-Permission Laravel Packget
Installation
1)Just add the following to your composer.json. Then run composer update
:
2) Open your config/app.php
and add the following to the providers
array:
3) In the same config/app.php
and add the following to the aliases
array:
4) Run the command below to publish the package config file config/roleper.php
:
5) If you want to use Middleware (requires Laravel 5.1 or later) you also need to add the following:
to routeMiddleware
array in app/Http/Kernel.php
.
copy to User.php
Checking for Roles & Permissions
Now we can check for roles and permissions simply by doing:
Both hasRole()
and can()
can receive an array of roles & permissions to check:
By default, if any of the roles or permissions are present for a user then the method will return true.
Passing true
as a second parameter instructs the method to require all of the items:
You can have as many Role
s as you want for each User
and vice versa.
Route
User
Next, use the RolePerUserTrait
trait in your existing User
model. For example:
php Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() { Route::get('/', 'AdminController@welcome'); Route::get('/manage', ['middleware' => ['permission:manage-admins'], 'uses' => 'AdminController@manageAdmins']); });
It is possible to use pipe symbol as *OR* operator:
To emulate *AND* functionality just use multiple instances of middleware
For more complex situations use `ability` middleware which accepts 3 parameters: roles, permissions, validate_all
All versions of roleper with dependencies
illuminate/console Version ~5.0
illuminate/support Version ~5.0
illuminate/cache Version ~5.0