@param Role    $role
@param Request $request

@return \Illuminate\Http\RedirectResponse
175091
public function save(Role $role, Request $request)
    {
        $role->fill($request->get('role'));

        foreach ($request->get('permissions', []) as $key => $value) {
            $permissions[base64_decode($key)] = 1;
        }

        $role->permissions = $permissions ?? [];
        $role->save();

        Alert::info(__('Role was saved'));

        return redirect()->route('platform.systems.roles');
    }
25529
public function addPolicy($roleId, Request $request)
    {
        $createStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        try {
            // First try to treat $roleId as a role draft ID.
            $role = $this->roleService->addPolicyByRoleDraft(
                $this->roleService->loadRoleDraft($roleId),
                $createStruct
            );
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->addPolicy(
                $this->roleService->loadRole($roleId),
                $createStruct
            );
        } catch (LimitationValidationException $e) {
            throw new BadRequestException($e->getMessage());
        }

        return new Values\CreatedPolicy(
            array(
                'policy' => $this->getLastAddedPolicy($role),
            )
        );
    }
871154
public function updatePolicy($roleId, $policyId, Request $request)
    {
        $updateStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        try {
            // First try to treat $roleId as a role draft ID.
            $role = $this->roleService->loadRoleDraft($roleId);
            foreach ($role->getPolicies() as $policy) {
                if ($policy->id == $policyId) {
                    try {
                        return $this->roleService->updatePolicy(
                            $policy,
                            $updateStruct
                        );
                    } catch (LimitationValidationException $e) {
                        throw new BadRequestException($e->getMessage());
                    }
                }
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);
            foreach ($role->getPolicies() as $policy) {
                if ($policy->id == $policyId) {
                    try {
                        return $this->roleService->updatePolicy(
                            $policy,
                            $updateStruct
                        );
                    } catch (LimitationValidationException $e) {
                        throw new BadRequestException($e->getMessage());
                    }
                }
            }
        }

        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }
1002403
public function handle($request, Closure $next, $role)
    {
        $this->authorize($role);

        return $next($request);
    }
27784
public function store(Request $request)
    {
        Role::create($request->all());

        session()->flash('success' , 'Rol creado con exito');
        return redirect()->route('roles.index');
    }
46706
public function addGroups(RoleGroup $request)
    {

        $this->giveGroupsRole(
            $request->input('groups'), $request->input('role_id'));

        return redirect()->back()
            ->with('success', trans('web::seat.user_added'));

    }
475995
public function store(Request $request, $role_id)
    {
    	$role = Role::findOrFail($role_id);
		if (isset($request->permission_id) && count($request->permission_id))
		{
			$role->permissions()->sync($request->permission_id);
		}
		else
		{
			$role->permissions()->sync(array());
		}
		$role->save();
		
		return redirect(url("/role/$role_id/permission"))->with('dp_announce', trans('deeppermission.alert.role_permission.updated'));
    }
684594
public function update(Role $role, FormRequest $request)
    {
        $data = $request->all();
        $roleData = Arr::except($data, ['exit', 'permissions']);
        $permissions = isset($data['permissions']) ? $data['permissions'] : [];
        $role->syncPermissions($permissions);
        $this->repository->update($role->id, $roleData);
        $role->forgetCachedPermissions();

        return $this->redirect($request, $role);
    }
479737
public function destroy(Role $role)
    {
        if (! $role->system) {
            try {
                $role->delete();

                return $this->notifySuccess('Role successfully deleted!');
            } catch (QueryException $e) {
                return $this->notifyError($e->getMessage());
            }
        }

        return $this->notifyError('Role is protected and cannot be deleted!');
    }
552678
public function addRole(Role $role): bool
    {
        return (new actions\AddRole($this->user, $role))->execute();
    }
1213824
public function store(Request $request)
    {
        $this->validate($request, ['name' => 'required']);

        $role = Role::create($request->all());
        $role->permissions()->detach();

        if ($request->has('permissions')) {
            foreach ($request->permissions as $permission_name) {
                $permission = Permission::whereName($permission_name)->first();
                $role->givePermissionTo($permission);
            }
        }

        return redirect('admin/roles')->with('flash_message', 'Role added!');
    }
713963
public function updateRoles(Request $request, User $user)
    {
        $this->authorize('roles', $user);

        $roles = Role::all();

        foreach ($roles as $role) {
            if (array_key_exists($role->id, $request->all())) {
                $role->addUser($user);
            } else {
                $role->deleteUser($user);
            }
        }

        return redirect()->route('laralum::users.index')->with('success', __('laralum_users::general.user_roles_updated', ['id' => $user->id]));
    }
173138
public function update(RoleRequest $request, $id)
    {
        $input = $request->except('permissions');

        $record = $this->model->findOrFail($id);

        $record->syncPermissions($request->permissions);

        $record->update($input);

        $this->notify([
            'type' => 'success',
            'title' => 'Successful update!',
            'description' => 'This role is updated successfully.',
        ]);

        return redirect()->back();
    }
1056221
public function handle($request, Closure $next, $role)
    {
        if (!Auth::user())
        {
            abort(503, "Unauthorized request");
        }

        if (!Auth::user()->hasRole($role))
        {
            abort(503, "Unauthorized request");
        }
        return $next($request);
    }
806639
public function roleEditAction(Request $request, $id)
    {
        /** @var \Doctrine\ORM\EntityManager $em */
        $em = $this->getDoctrine()->getManager();

        $role = $em->find(Role::class, $id);

        $form = $this->createForm(RoleFormType::class, $role);

        if ($request->isMethod('POST')) {
            $form->handleRequest($request);
            if ($form->isValid()) {
                $this->persist($role, true);

                $this->addFlash('success', 'Роль обновлена.');

                return $this->redirect($this->generateUrl('cms_admin_user_roles'));
            }
        }

        return $this->render('@CMS/AdminUser/role_edit.html.twig', [
            'form' => $form->createView(),
        ]);
    }
121315
public function addRole(\Amulen\UserBundle\Entity\Role $role)
    {
        $this->roles[] = $role;

        return $this;
    }
173851
public function postSearchWithRole(Request $request)
    {
        $query = $this->model->where('role_id', '=', $request->get('role'));
        $this->postSearch($request, $query);

        return $this->postSearch($request, $query);
    }