Devise\Users\UserManager::updateUser PHP Method

updateUser() public method

Update a new user
public updateUser ( integer $id, array $input ) : DvsUser
$id integer
$input array
return DvsUser
    public function updateUser($id, $input)
    {
        $validator = $this->Validator->make($input, $this->updateRules($id, $input), $this->messages);
        if ($validator->passes()) {
            $user = $this->DvsUser->findOrFail($id);
            $user->activated = array_get($input, 'activated', false);
            $user->name = array_get($input, 'name', null);
            $user->email = array_get($input, 'email');
            $user->username = array_get($input, 'username', null);
            if (array_get($input, 'password', null)) {
                $user->password = $this->Hash->make(array_get($input, 'password'));
            }
            $user->save();
            $user->groups()->sync(array_get($input, 'group_id', []));
            return $user;
        }
        $this->errors = $validator->errors()->all();
        $this->message = "There were validation errors.";
        return false;
    }

Usage Example

Example #1
0
 /**
  * Request user be updated with a given input
  *
  * @param  integer $id
  * @param  array   $input
  * @return Redirector
  */
 public function requestUpdateUser($id, $input)
 {
     if ($this->UserManager->updateUser($id, $input)) {
         return $this->Redirect->route('dvs-users')->with('message', 'User successfully updated');
     }
     return $this->Redirect->route('dvs-users-edit', $id)->withInput()->withErrors($this->UserManager->errors)->with('message', $this->UserManager->message);
 }