Skip to content

Assign Permissions to Role

Kodeine edited this page Feb 23, 2015 · 1 revision

Assign Permission(s) to Role

Lets assign created permissions to a Role.

Note: You can pass an object, an array, role->id or just name.

$roleAdmin = Role::first(); // administrator
// permission as an object
$roleAdmin->assignPermission($permUser);
// as an id
$roleAdmin->assignPermission($permUser->id);
// or by name
$roleAdmin->assignPermission('user');

Or multiple permissions at once:

// multiple permissions in an array
$roleAdmin->assignPermission(array($permUser, $permPost->id));
// or mutiple role slugs separated by comma or pipe.
$roleAdmin->assignPermission('user, 'post');

Note: The system will throw an exception if permission does not exists.