Exemplo n.º 1
0
 /**
  * Display a listing of the resource.
  * GET /posts/{id}/comments
  *
  * @param int $id
  * @return Response
  */
 public function index($id)
 {
     if (Input::has('size') || Input::get('size') > 61) {
         $max = Input::get('size');
     } else {
         $max = 25;
     }
     if (Input::has('timestamp')) {
         $comments = Comment::byTimestampAndPost(Input::get('timestamp'), $id)->orderBy('id', 'desc')->take($max)->get();
     } elseif (Input::has('last')) {
         $comments = Comment::byLastAndPost(Input::get('last'), $id)->take($max)->orderBy('id', 'desc')->get();
     } else {
         $comments = Comment::byPost($id)->orderBy('id', 'desc')->take($max)->get();
     }
     if ($comments->isEmpty()) {
         return $this->respond([]);
     }
     return $this->respond($this->collectionTransformer->transformComments($comments));
 }
Exemplo n.º 2
0
 /**
  * Display the specified resource.
  * GET /posts/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $user = Auth::user();
     $post = Post::find($id);
     if (Input::has('size')) {
         $size = Input::get('size') <= 25 ? Input::get('size') : $this->max;
     } else {
         $size = $this->max;
     }
     if (!$post) {
         return $this->respondNotFound();
     }
     $comments = $post->comments()->orderBy('id', 'desc')->take($size)->get();
     if (!$comments->isEmpty()) {
         $post = $this->collectionTransformer->transformPost($post, $user->favorites, $user->subscriptions);
         $comments = $this->collectionTransformer->transformComments($comments);
         return $this->respond(['post' => $post, 'comments' => $comments]);
     } else {
         return $this->respond(['post' => $this->collectionTransformer->transformPost($post, $user->favorites, $user->subscriptions), 'comments' => []]);
     }
     return $this->respondServerError();
 }