Save the role.

@param  \Orchestra\Model\Role  $role
@param  array  $input
@param  string  $type

@return bool
497071
protected function saving(Eloquent $role, $input = [], $type = 'create')
    {
        $beforeEvent = ($type === 'create' ? 'creating' : 'updating');
        $afterEvent = ($type === 'create' ? 'created' : 'updated');

        $role->setAttribute('name', $input['name']);

        $this->fireEvent($beforeEvent, [$role]);
        $this->fireEvent('saving', [$role]);

        DB::transaction(function () use ($role) {
            $role->save();
        });

        $this->fireEvent($afterEvent, [$role]);
        $this->fireEvent('saved', [$role]);

        return true;
    }
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);
    }
548934
public function revokeRole(Role $role): bool
    {
        return (new actions\RevokeRole($this->user, $role))->execute();
    }
414987
public function update(Request $request, Role $role)
    {
        $this->authorize('update', Role::class);
        $this->validate($request, [
            'name'        => 'required|max:255',
            'color'       => 'required|size:7',
            'description' => 'required|max:500',
        ]);
        $role->update($request->all());

        return redirect()->route('laralum::roles.index')->with('success', __('laralum_roles::general.role_updated', ['id' => $role->id]));
    }
863948
private function createUserWithRole(Role $role)
    {
        $userService = $this->getRepository()->getUserService();
        $username = uniqid($role->identifier, true);
        $createStruct = $userService->newUserCreateStruct(
            $username,
            $username . '@example.com',
            self::$password,
            'eng-GB'
        );
        $createStruct->setField('first_name', $username);
        $createStruct->setField('last_name', 'The first');
        $user = $userService->createUser($createStruct, [$userService->loadUserGroup(self::$groupId)]);

        $this->getRepository()->getRoleService()->assignRoleToUser($role, $user);

        return $user;
    }
223153
public function store($listener, array $input)
    {
        $validation = $this->validator->on('create')->with($input);

        if ($validation->fails()) {
            return $listener->storeValidationFailed($validation);
        }

        $role = $this->model;

        try {
            $this->saving($role, $input, 'create');
        } catch (Exception $e) {
            return $listener->storeFailed(['error' => $e->getMessage()]);
        }

        return $listener->storeSucceed($role);
    }
664604
public function addRole(string ...$role)
    {
        foreach ($role as $_role)
        {
            $this->roleRegistry->save($_role);
        }
    }
1308743
public function save(string $role, ...$options)
    {
        $resource = $options[0];
        $permission = $options[1];
        $status = (isset($options[2])) ? $options[2] : true;

        $this->registry[$role][$resource][$permission]["status"] = $status;
    }
1013271
public function updated(Role $role)
    {
        $oldRole = new Role($role->getOriginal());
        $oldRoleName = $oldRole->snake_case_name;
        $newRoleName = $role->snake_case_name;
        if ($newRoleName != $oldRoleName) {
            $this->updateLanguageTerm($oldRoleName, $newRoleName);
        }
    }
414715
private function createCreateForm(Role $entity) {
        $form = $this->createForm(new RoleType, $entity, array(
            'action' => $this->generateUrl('admin_role_create'),
            'method' => 'POST',
        ));

        $form->add('submit', 'submit', array('label' => 'Create'));

        return $form;
    }
1223098
public function storeRolePermission(Role $role, Permission $permission)
    {
        $this->getTable()->insert([
            'role' => $role->getRoleName(),
            'type' => $permission->getType(),
            'action' => $permission->getAction(),
            'resource_type' => $permission->getResourceType(),
            'resource_id' => $permission->getResourceId(),
        ]);

        $this->resetPermissionsCacheForRole($role);
    }
76704
public static function createFromConfiguration ($role, array $configuration)
    {
        return new Role(
            $role,
            isset($configuration["title"]) ? $configuration["title"] : null,
            isset($configuration["description"]) ? $configuration["description"] : null,
            isset($configuration["hidden"]) ? $configuration["hidden"] : false,
            isset($configuration["tags"]) ? $configuration["tags"] : [],
            isset($configuration["actions"]) ? $configuration["actions"] : []
        );
    }
501942
public function createAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'assign'));
        $form = $this->formFactory->createRoleAssignment(new RoleAssignmentCreateData());
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (RoleAssignmentCreateData $data) use ($role) {
                foreach ($this->createLimitations($data) as $limitation) {
                    foreach ($data->getUsers() as $user) {
                        $this->roleService->assignRoleToUser($role, $user, $limitation);
                    }
                    foreach ($data->getGroups() as $group) {
                        $this->roleService->assignRoleToUserGroup($role, $group, $limitation);
                    }
                }

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Assignments on role '%role%' created.") */
                        'role.assignment_create.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $role->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->render('@ezdesign/admin/role_assignment/create.html.twig', [
            'role' => $role,
            'form' => $form->createView(),
        ]);
    }
377996
public function store(RoleRequest $request)
    {
        try {
            $role = $this->repository->create($request->all());
            $this->_saveRolePermissions($request, $role);
        } catch (\Exception $e) {
            echo 'Caught exception: ', $e->getMessage(), "\n";
        }

        return redirect()->route('admin.role.index')->with('notificationText', ' New Role has been Created Successfully!');
    }
984913
public void setRole(java.lang.String role) {
        getStateHelper().put(PropertyKeys.role, role);
        handleAttribute("role", role);
    }
518069
public function InsertForBasic($FormPostValues, $CheckCaptcha = TRUE, $Options = array()) {
      $RoleIDs = Gdn::Config('Garden.Registration.DefaultRoles');
      if (!is_array($RoleIDs) || count($RoleIDs) == 0)
         throw new Exception(T('The default role has not been configured.'), 400);
      
      if (GetValue('SaveRoles', $Options)) {
         $RoleIDs = GetValue('RoleID', $FormPostValues);
      }

      $UserID = FALSE;

      // Define the primary key in this model's table.
      $this->DefineSchema();

      // Add & apply any extra validation rules.
      if (GetValue('ValidateEmail', $Options, TRUE))
         $this->Validation->ApplyRule('Email', 'Email');

      // TODO: DO I NEED THIS?!
      // Make sure that the checkbox val for email is saved as the appropriate enum
      if (array_key_exists('ShowEmail', $FormPostValues))
         $FormPostValues['ShowEmail'] = ForceBool($FormPostValues['ShowEmail'], '0', '1', '0');
      
      if (array_key_exists('Banned', $FormPostValues))
         $FormPostValues['Banned'] = ForceBool($FormPostValues['Banned'], '0', '1', '0');

      $this->AddInsertFields($FormPostValues);

      if ($this->Validate($FormPostValues, TRUE) === TRUE) {
         $Fields = $this->Validation->ValidationFields(); // All fields on the form that need to be validated (including non-schema field rules defined above)
         $Username = ArrayValue('Name', $Fields);
         $Email = ArrayValue('Email', $Fields);
         $Fields = $this->Validation->SchemaValidationFields(); // Only fields that are present in the schema
         $Fields['Roles'] = $RoleIDs;
         $Fields = RemoveKeyFromArray($Fields, $this->PrimaryKey);

         // If in Captcha registration mode, check the captcha value
         if ($CheckCaptcha && Gdn::Config('Garden.Registration.Method') == 'Captcha') {
            $CaptchaPublicKey = ArrayValue('Garden.Registration.CaptchaPublicKey', $FormPostValues, '');
            $CaptchaValid = ValidateCaptcha($CaptchaPublicKey);
            if ($CaptchaValid !== TRUE) {
               $this->Validation->AddValidationResult('Garden.Registration.CaptchaPublicKey', 'The reCAPTCHA value was not entered correctly. Please try again.');
               return FALSE;
            }
         }

         if (!$this->ValidateUniqueFields($Username, $Email))
            return FALSE;
         
         // Check for spam.
         if (GetValue('ValidateSpam', $Options, TRUE)) {
            $ValidateSpam = $this->ValidateSpamRegistration($FormPostValues);
            if ($ValidateSpam !== TRUE)
               return $ValidateSpam;
         }

         // Define the other required fields:
         $Fields['Email'] = $Email;

         // And insert the new user
         $UserID = $this->_Insert($Fields, $Options);
         if ($UserID && !GetValue('NoActivity', $Options)) {
            $ActivityModel = new ActivityModel();
            $ActivityModel->Save(array(
               'ActivityUserID' => $UserID,
               'ActivityType' => 'Registration',
               'HeadlineFormat' => T('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'),
               'Story' => T('Welcome Aboard!')
                ),
                FALSE,
                array('GroupBy' => 'ActivityTypeID'));
         }
      }
      return $UserID;
   }
568442
public function attachRole($role)
    {
        if(is_object($role)) {
            $role = $role->getKey();
        }

        if(is_array($role)) {
            $role = $role['id'];
        }

        $this->roles()->attach($role);

        self::clearCache();
    }