基本上你必须..
创建您的群组
Sentry::getGroupProvider()->create([
'name' => 'Super Administrators',
'permissions' => [
'system' => 1,
],
]);
Sentry::getGroupProvider()->create([
'name' => 'Managers',
'permissions' => [
'system.products' => 1,
'system.store' => 1,
'system.profile' => 1,
],
]);
将组设置为特定用户,在这种情况下,它将 Managers 设置为当前登录的用户
Sentry::getUser()->addGroup( Sentry::getGroupProvider()->findByName('Managers') );
检查用户是否具有特定访问权限
if ( Sentry::getUser()->hasAnyAccess(['system','system.products']) )
{
// Will be able to do a thing
}
检查用户是否是超级管理员(只有该组具有“系统”访问权限)
if ( Sentry::getUser()->hasAnyAccess(['system']) )
{
// Will be able to do a thing
}
获取特定用户的所有组
try
{
// Find the user using the user id
$user = Sentry::getUserProvider()->findById(1);
// Get the user groups
$groups = $user->getGroups();
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
echo 'User was not found.';
}