本文整理汇总了PHP中app\models\Role::attachPermissions方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::attachPermissions方法的具体用法?PHP Role::attachPermissions怎么用?PHP Role::attachPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Role
的用法示例。
在下文中一共展示了Role::attachPermissions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* @param $input
* @throws GeneralException
* @return bool
*/
public function create($input)
{
if (Role::where('role_name', $input['role_name'])->first()) {
throw new GeneralException('That role already exists. Please choose a different name.');
}
if (count($input['assignees_permissions']) == 0) {
throw new GeneralException('You must select at least one permission for this role.');
}
$role = new Role();
$role->role_name = $input['role_name'];
$role->role_slug = $input['role_slug'];
$role->role_description = $input['role_description'];
if ($role->save()) {
$current = $input['assignees_permissions'];
$permissions = [];
if (count($current)) {
foreach ($current as $perm) {
if (is_numeric($perm)) {
array_push($permissions, $perm);
}
}
}
$role->attachPermissions($permissions);
return true;
}
throw new GeneralException('There was a problem creating this role. Please try again.');
}
示例2: setupRolesPermissions
public function setupRolesPermissions()
{
$master = User::findOrFail(1);
if ($master) {
// Create role
$owner = new Role();
$owner->name = 'master';
$owner->display_name = 'Project Owner';
$owner->description = 'The Master of Universe';
$owner->save();
// Create permissions
$createUser = new Permission();
$createUser->name = 'user-create';
$createUser->display_name = 'Create Users';
$createUser->description = 'Create new users';
$createUser->save();
$editUser = new Permission();
$editUser->name = 'user-edit';
$editUser->display_name = 'Edit Users';
$editUser->description = 'Edit existing users';
$editUser->save();
$deleteUser = new Permission();
$deleteUser->name = 'user-delete';
$deleteUser->display_name = 'Delete Users';
$deleteUser->description = 'Delete existing users';
$deleteUser->save();
// Attach permissions
$owner->attachPermissions([$createUser, $editUser, $deleteUser]);
// Attach roles
$master->attachRole($owner);
// using facade
}
return redirect()->route('access.test');
}
示例3: EventManager
public static function EventManager($eventId, $permissions)
{
return DB::transaction(function () use($eventId, $permissions) {
$rolename = RoleNames::EventManager($eventId);
$role = new Role();
$role->name = $rolename;
$role->save();
$role->attachPermissions($permissions);
return $role;
});
}