From a9e7e281f2a102db6a223b7a54ade5deb56fbffe Mon Sep 17 00:00:00 2001 From: Yury Kabanov Date: Sat, 6 Aug 2016 15:27:36 +0700 Subject: [PATCH] Fix pagination used default eloquent's page size (fix #76) --- .../Laravel5/JsonApi/Controller/JsonApiTrait.php | 2 +- .../Laravel5/JsonApi/Eloquent/EloquentHelper.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php index 8127605..133f49a 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php +++ b/src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php @@ -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(); }; } diff --git a/src/NilPortugues/Laravel5/JsonApi/Eloquent/EloquentHelper.php b/src/NilPortugues/Laravel5/JsonApi/Eloquent/EloquentHelper.php index 3d225d8..7533d01 100644 --- a/src/NilPortugues/Laravel5/JsonApi/Eloquent/EloquentHelper.php +++ b/src/NilPortugues/Laravel5/JsonApi/Eloquent/EloquentHelper.php @@ -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()