Skip to content

C. User Groups & Permission

darryl fernandez edited this page Oct 12, 2017 · 1 revision

Get current logged in user

$User = \Auth::user();

check if a user belongs to a group

$group = 1; // using group ID

$group = 'members'; // or using group name

$group = $GroupObject; // or the group object

$User->inGroup($group); // returns true or false

Check if User has the given permission

$permission = 'blog.create';

$UserObject->hasPermission($permission); // returns true or false

// or a set of any of this permissions $permissions = array('blog.create','blog.delete');

$UserObject->hasAnyPermission($permissions); // returns true or false

Check if User is a superuser:

$UserObject->isSuperUser();

Get User's combined permissions. This will include permission acquired from its group and its specific given permissions:

$UserObject->getCombinedPermissions(); // returns array of permissions