/** * DELETE method: Delete user * * @param Request $request * @throws Exception * @return mixed */ public function delete($request) { switch (count($request->url_elements)) { case 2: // Don't have permissions - throw Exception if (!Application::isAdmin()) { throw new Exception("You don't have required permissions to update this user.", 403); } // Like success - delete user & return $user = User::find_by_id($request->url_elements[1]); if ($user) { $user->delete(); return json_decode($user->to_json(array('except' => 'password'))); } else { throw new Exception("User not found.", 404); } default: throw new Exception("Unknown request.", 500); } }