コード例 #1
0
 /**
  * @api            {get} /tasks/:slug/posts Get Task Posts
  * @apiGroup       Task Posts
  * @apiDescription Get posts for a task.
  *
  * @param Request $request
  * @param Task    $task
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request, Task $task)
 {
     $this->validate($request, ['type' => 'in:submission,question,tip']);
     if ($type = $request->input('type')) {
         $posts = $task->posts()->where('type', $type);
     } else {
         $posts = $task->posts();
     }
     // TODO: Order by best unless type filter is given then order by most recent
     $posts = $posts->orderBy('id', 'DESC');
     $paginator = $posts->paginate($this->getResultsPerPage());
     return $this->response($this->paginatorToArray($paginator, 'posts'));
 }