Example #1
0
 /**
  * Include comments.
  *
  * @param  \App\Book $book
  * @param  \League\Fractal\ParamBag|null $params
  * @return  \League\Fractal\Resource\Collection
  * @throws  \Exception
  */
 public function includeComments(Book $book, $params)
 {
     if ($params) {
         $this->validateParams($params);
     }
     list($limit, $offset) = $params->get('limit') ?: config('api.include.limit');
     list($orderCol, $orderBy) = $params->get('order') ?: config('api.include.order');
     $comments = $book->comments()->limit($limit)->offset($offset)->orderBy($orderCol, $orderBy)->get();
     return $this->collection($comments, new \App\Transformers\CommentTransformer());
 }