validate([ 'currentPassword' => 'required|string', 'newPassword' => 'required|string', 'newPasswordConfirmation' => 'required|string', ]); $guard = $this->passwordAccountGuard(); $account = Auth::guard($guard)->user(); if (! Hash::check($this->currentPassword, $account->password)) { $this->addError('currentPassword', __('admin_settings.password_wrong')); return; } if ($guard === 'web') { try { app(UpdateUserPassword::class)->update($account, [ 'current_password' => $this->currentPassword, 'password' => $this->newPassword, 'password_confirmation' => $this->newPasswordConfirmation, ]); } catch (ValidationException $e) { foreach ($e->errors() as $field => $messages) { $this->addError(match ($field) { 'current_password' => 'currentPassword', 'password' => 'newPassword', default => $field, }, $messages[0]); } return; } } else { try { Validator::make([ 'password' => $this->newPassword, 'password_confirmation' => $this->newPasswordConfirmation, ], ['password' => $this->passwordRules()])->validate(); } catch (ValidationException $e) { $this->addError('newPassword', $e->errors()['password'][0]); return; } $account->forceFill(['password' => Hash::make($this->newPassword)])->save(); } $this->reset('currentPassword', 'newPassword', 'newPasswordConfirmation'); $this->dispatch('notify', message: __('admin_settings.password_changed')); } }