-
Notifications
You must be signed in to change notification settings - Fork 216
Create User Permissions
Kodeine edited this page Feb 23, 2015
·
16 revisions
User permissions work same way as role permissions except the fact user permissions override the default role permissions.
An alias has set of permissions stored as json in database.
$user = User::first();
// create crud permissions
// create.user, view.user, update.user, delete.user
// returns false if alias exists.
$user->addPermission('user');
// update permission on user alias
// set its permission to false
$user->addPermission('update.user', false);
$user->addPermission('view.phone.user', true);
// pass permissions array to user alias
$user->addPermission('user', [
'view.phone' => true,
'view.blog' => false
]);
Note: If alias or permission already exists, it will update the existing permission's value.
// remove an alias
$user->removePermission('user');
// remove update permission from user
$user->removePermission('update.user');
$user->removePermission('user', [
'view.phone'
'view.blog'
]);
Get permissions assigned to a user. An array of key value pairs are returned having user permissions along with its role permissions. Of course user permissions override role ones.
$user = User::first();
$user->getPermissions();