-
Notifications
You must be signed in to change notification settings - Fork 216
Validate Permissions and Roles
Kodeine edited this page Mar 7, 2015
·
9 revisions
Roles can be validated by calling is
method.
Validate based on User.
Method is() supports comma for AND and pipe as OR operator. Or you can pass operator as a second param.
$user = User::first();
$user->is('administrator');
$user->isAdministrator(); // using method
// using pipe as OR operator
// any one role allowed will result to true.
$user->is('administrator|moderator');
// using comma as AND operator
// all roles defined must be allowed to result true.
$user->is('administrator,moderator');
// or pass second param as operator
$user->is(array('administrator', 'moderator'), 'or');
Permissions can be validated by calling can
method.
Validate based on Role.
Method can() supports comma for AND and pipe as OR operator. Or you can pass operator as a second param.
$admin = Role::first(); // administrator
$admin->can('view.user');
$admin->canViewUser(); // using method.
// by an array
$admin->can(array('view.user', 'edit.user'));
// by an array with or operator
$admin->can(array('view.user', 'edit.user'), 'or');
// using pipe as OR operator
// any allowed permission will result to true.
$admin->can('view.user|edit.user|view.admin|delete.admin');
// using comma as AND operator
// all permissions defined must be allowed to result true.
$admin->can('view.user,edit.user,view.admin,delete.admin');
Validate based on User
$user = User::first();
$user->can('delete.user');
$user->canDeleteUser(); // using method