-
Notifications
You must be signed in to change notification settings - Fork 216
Assign Roles To User
Kodeine edited this page Feb 23, 2015
·
3 revisions
Lets assign created roles to a User.
Note: You can pass an object, an array, role->id or just a slug.
$user = User::find(1);
// by object
$user->assignRole($roleAdmin);
// or by id
$user->assignRole($roleAdmin->id);
// or by just a slug
$user->assignRole('administrator');
Or multiple roles
at once:
// multiple roles in an array
$user->assignRole(array($roleAdmin, $roleModerator));
// or mutiple role slugs separated by comma or pipe.
$user->assignRole('administrator, moderator');
Note: The system will throw an exception if role does not exists.