public function deleteUser(Request $request, $id) { try { $repo = new UserRepository(); $repo->delete($id); Alert::success('Successfully deleted user from system.')->flash(); return redirect()->route('admin.users'); } catch (DisplayException $ex) { Alert::danger($ex->getMessage())->flash(); } catch (\Exception $ex) { Log::error($ex); Alert::danger('An exception was encountered while attempting to delete this user.')->flash(); } return redirect()->route('admin.users.view', $id); }
/** * Delete a User * * @Delete("/users/{id}") * @Versions({"v1"}) * @Transaction({ * @Request(headers={"Authorization": "Bearer <token>"}), * @Response(204), * @Response(422) * }) * @Parameters({ * @Parameter("id", type="integer", required=true, description="The ID of the user to delete.") * }) */ public function delete(Request $request, $id) { try { $user = new UserRepository(); $user->delete($id); return $this->response->noContent(); } catch (DisplayException $ex) { throw new ResourceException($ex->getMessage()); } catch (\Exception $ex) { throw new ServiceUnavailableHttpException('Unable to delete this user due to an error.'); } }