public function updateUser(Request $request, $user) { $data = ['email' => $request->input('email'), 'root_admin' => $request->input('root_admin'), 'password_confirmation' => $request->input('password_confirmation')]; if ($request->input('password')) { $data['password'] = $request->input('password'); } try { $repo = new UserRepository(); $repo->update($user, $data); Alert::success('User account was successfully updated.')->flash(); } catch (DisplayValidationException $ex) { return redirect()->route('admin.users.view', $user)->withErrors(json_decode($ex->getMessage())); } catch (\Exception $e) { Log::error($e); Alert::danger('An error occured while attempting to update this user.')->flash(); } return redirect()->route('admin.users.view', $user); }
/** * Update an Existing User * * The data sent in the request will be used to update the existing user on the system. * * @Patch("/users/{id}") * @Versions({"v1"}) * @Transaction({ * @Request({ * "email": "*****@*****.**" * }, headers={"Authorization": "Bearer <token>"}), * @Response(200, body={"email": "*****@*****.**"}), * @Response(422) * }) * @Parameters({ * @Parameter("id", type="integer", required=true, description="The ID of the user to modify.") * }) */ public function update(Request $request, $id) { try { $user = new UserRepository(); $user->update($id, $request->all()); return Models\User::findOrFail($id); } catch (DisplayValidationException $ex) { throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); } catch (DisplayException $ex) { throw new ResourceException($ex->getMessage()); } catch (\Exception $ex) { throw new ServiceUnavailableHttpException('Unable to update a user on the system due to an error.'); } }