response->paginator($servers, new ServerTransformer); } /** * List Specific Server * * Lists specific fields about a server or all fields pertaining to that server. * * @Get("/servers/{id}/{fields}") * @Versions({"v1"}) * @Parameters({ * @Parameter("id", type="integer", required=true, description="The ID of the server to get information on."), * @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.") * }) * @Response(200) */ public function getServer(Request $request, $id) { $query = Models\Server::where('id', $id); if (!is_null($request->input('fields'))) { foreach(explode(',', $request->input('fields')) as $field) { if (!empty($field)) { $query->addSelect($field); } } } try { if (!$query->first()) { throw new NotFoundHttpException('No server by that ID was found.'); } return $query->first(); } catch (NotFoundHttpException $ex) { throw $ex; } catch (\Exception $ex) { throw new BadRequestHttpException('There was an issue with the fields passed in the request.'); } } }