Most of medium/big projects needs to users roles so we provide to you the easy way.
You can create multilingual role, you can use the way that you prefer.
1use Pharaonic\Laravel\Users\Models\Roles\Role; 2 3// Way 1 4Role::create('admin', 'Administrator'); 5 6// Way 2 7Role::create('admin', 'Administrator', 'en'); 8 9// Way 310Role::create('admin', [11 'ar' => 'إداري',12 'en' => 'Administrator'13]);
Attach permission to the role.
1use Pharaonic\Laravel\Users\Models\Roles\Role;2 3$role = Role::findByCode('admin');4$role->permit('post.create', 'post.edit', 'post.delete');
This is how you can include the role into your user model.
1namespace App\Models;2 3use Pharaonic\Laravel\Users\Traits\HasRoles; 4 5class User extends Authenticatable6{7 use HasRoles; 8}
Giving the user one or many roles.
1$user->entrust('DevOps', 'Developer');2// Returns Boolean
Check if the user has one of these roles.
1$user->entrustedAny(['Developer', 'Musician']);2// Returns Boolean
Distrusting the user from having these roles.
1$user->distrust('Musician');2// Returns Boolean
Check if the user has not all these roles.
1$user->distrusted(['CEO', 'CFO']);2// Returns Boolean
Check if the user has not one of these roles.
1$user->distrustedAny(['CEO', 'CFO', 'Musician']);2// Returns Boolean
Clear all user roles and give him/her these list.
1$user->syncRoles('CEO', 'Developer', 'Musician');2// Returns Boolean
You can use middlewares to strict your routes.
1Route::middleware('entrusted:CFO')->group(...);2Route::middleware('entrustedAny:CFO,CEO')->group(...);