Skip to content

Commit

Permalink
Merge pull request #87 from yurykabanov/issue-76
Browse files Browse the repository at this point in the history
Fix pagination used default eloquent's page size (fix #76)
  • Loading branch information
nilportugues authored Aug 6, 2016
2 parents 443012d + a9e7e28 commit b92bbd5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract public function getDataModel();
protected function listResourceCallable()
{
return function () {
return EloquentHelper::paginate($this->serializer, $this->getDataModel()->query())->get();
return EloquentHelper::paginate($this->serializer, $this->getDataModel()->query(), $this->pageSize)->get();
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/NilPortugues/Laravel5/JsonApi/Eloquent/EloquentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ trait EloquentHelper
/**
* @param JsonApiSerializer $serializer
* @param Builder $builder
* @param int $pageSize
*
* @return Builder
*/
public static function paginate(JsonApiSerializer $serializer, Builder $builder)
public static function paginate(JsonApiSerializer $serializer, Builder $builder, $pageSize = null)
{
self::sort($serializer, $builder, $builder->getModel());

$request = RequestFactory::create();

$builder->paginate(
$request->getPage()->size(),
$request->getPage()->size() ?: $pageSize,
self::columns($serializer, $request->getFields()->get()),
'page',
$request->getPage()->number()
Expand Down

0 comments on commit b92bbd5

Please sign in to comment.