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)) { 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, [