kilroyweb / roles by kilroyweb

Support for user roles
68
0
1
Package Data
Maintainer Username: kilroyweb
Package Create Date: 2017-06-28
Package Last Update: 2017-06-28
Language: PHP
License: MIT
Last Refreshed: 2024-11-21 03:01:13
Package Statistics
Total Downloads: 68
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

Installation

composer require kilroyweb/roles

Add to the $routeMiddleware array in app/Http/Kernel.php

'role' => \KilroyWeb\Roles\Middleware\AuthHasRole::class,

Add the HasRole trait to your User class

use \KilroyWeb\Roles\Traits\HasRole;

Routes

Use the supplied "role" middleware to pass allowed roles

Route::prefix('/manage')->middleware(['auth','role:admin,employee'])->group(function(){
    ...
});

Available Methods

Use the roleIs and roleIn methods to check a user's role:

if($user->roleIs('admin)){
    //user is admin role
}

if($user->roleIn(['admin','manager'])){
    //user is admin or manager role
}