1. Go to this page and download the library: Download miracuthbert/laravel-roles library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$user->revokeRoles();
// with an array of values
$user->revokeRoles(['admin-root', 'admin-basic']);
$user->detachRoles();
// with an array of values
$user->detachRoles(['admin-root', 'admin-basic']);
if($user->hasRole('admin-root')) {
// user can do something as admin
}
if($user->hasRole(['admin-root', 'manager', 'editor'])) {
// user can do something as admin
}
if($user->hasRole('admin-root', 'manager', 'editor')) {
// user can do something as admin
}
// Just role
Route::middleware(['role:admin-root'])->get('/admin/logs');
// Via role and permission
Route::middleware(['role:admin-root,delete-admins'])->delete('/admin/roles/editors/revoke');
public function __construct() {
// Via permission name `browse admin`
$this->middleware(['role:admin-root']);
// Via role and permission (slug or name)
$this->middleware(['role:admin-root,delete-admins']);
}
if(Gate::allows('browse-admin')) {
// do something
}
// With giver
if(Gate::allows('browse-admin', $team)) {
// do something
}
if(Gate::denies('browse-admin')) {
return abort(403);
}
// With giver
if(Gate::denies('browse-admin', $team)) {
return abort(403);
}
if($user->can('assign roles')) {
// do something
}
// With giver
if($user->can('assign roles', $team)) {
// do something
}
// Via permission name `browse admin`
Route::middleware(['permission: browse admin'])->get('/admin/dashboard');
// Via permission slug `browse-admin`
Route::middleware(['permission: browse-admin'])->get('/admin/dashboard');
public function __construct() {
// Via permission name `browse admin`
$this->middleware(['permission: browse admin']);
// Via permission slug `browse-admin`
$this->middleware(['permission: browse-admin']);
// Via permission name `browse admin` with giver, the id should be fetched from the request or dynamically resolved
$this->middleware(['permission: browse admin, team:' . $request->team]);
// Via permission slug `browse-admin` with giver, the id should be fetched from the request or dynamically resolved
$this->middleware(['permission: browse-admin, team:' . $request->team]);
}
blade
@can('impersonate user')
<!-- The user can impersonate another user -->
@endcan
// With giver
@can('impersonate user', $team)
<!-- The user can impersonate another user -->
@endcan
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.