From f0c30cdd2fb371d7fa03ada06b66655d8ae82766 Mon Sep 17 00:00:00 2001 From: manandhar Date: Tue, 19 Sep 2017 16:23:35 +0545 Subject: [PATCH 1/2] page to start from 1 --- src/EloquentBuilderTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EloquentBuilderTrait.php b/src/EloquentBuilderTrait.php index c54e631..173a1a5 100644 --- a/src/EloquentBuilderTrait.php +++ b/src/EloquentBuilderTrait.php @@ -58,7 +58,7 @@ protected function applyResourceOptions(Builder $queryBuilder, array $options = throw new InvalidArgumentException('A limit is required when using page.'); } - $queryBuilder->offset($page * $limit); + $queryBuilder->offset(($page > 0 ? $page - 1 : 0) * $limit); } if (isset($distinct)) { From 4b6e7289ae32417b0508b91b6ce294e75a1df683 Mon Sep 17 00:00:00 2001 From: manandhar Date: Tue, 19 Sep 2017 16:24:23 +0545 Subject: [PATCH 2/2] fix test for page to start from 1 --- tests/EloquentBuilderTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EloquentBuilderTraitTest.php b/tests/EloquentBuilderTraitTest.php index 6bee22b..89bb92f 100644 --- a/tests/EloquentBuilderTraitTest.php +++ b/tests/EloquentBuilderTraitTest.php @@ -15,7 +15,7 @@ public function testParametersAreAppliedCorrectly() ])); $mock->shouldReceive('orderBy')->once()->with('property', 'DESC'); $mock->shouldReceive('limit')->once()->with(20); - $mock->shouldReceive('offset')->once()->with(40); + $mock->shouldReceive('offset')->once()->with(20); $mock->shouldReceive('where')->once()->with(m::type('callable')); $this->applyResourceOptions($mock, [