1. Go to this page and download the library: Download trunow/rpac library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
trunow / rpac example snippets
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
Illuminate\Auth\AuthServiceProvider::class,
...
/**
* Third Party Service Providers...
*/
Trunow\Rpac\RpacServiceProvider::class,
],
useApp\User;
$user = User::find($id);
$user->roles()->attach($adminRole); // you can pass whole object, or just an id
$user->roles()->detach($adminRole); // in case you want to detach role
$user->roles()->detach(); // in case you want to detach all roles
if ($user->is('admin')) { // pass role slug here// ...
}
if ($user->isAdmin()) {
//
}
if ($user->is(['admin', 'moderator'])) {
/*
| It is same as:
| $user->isOr(['admin', 'moderator'])
*/// if user has at least one role
}
if ($user->is(['admin', 'moderator'], true)) {
/*
| Or alternatively:
| $user->isAnd(['admin', 'moderator'])
*/// if user has all roles
}
useTrunow\Rpac\Role;
$role = Role::find($roleId);
$role->permissions()->attach($createPostPermission); // permission attached to a role
$role->permissions()->detach($createPostPermission); // in case you want to detach permission
$role->permissions()->detach(); // in case you want to detach all permissions