Skip to content

Commit

Permalink
IMPROVEMENT Add existing query params to pagination links (#30)
Browse files Browse the repository at this point in the history
* Add existing query params to pagingation links

* Add appends method to mock object for passing tests
  • Loading branch information
Steven Richardson authored and dominicmartineau committed Jul 14, 2016
1 parent 3b16343 commit 74d0641
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Laravel/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function withArray(array $array, array $headers = [])
*/
public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = [])
{
$queryParams = array_diff_key($_GET, array_flip(['page']));
$paginator->appends($queryParams);

$resource = new Collection($paginator->items(), $transformer, $resourceKey);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));

Expand Down
1 change: 1 addition & 0 deletions tests/Laravel/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testWithPaginatorWorkProperly()
$paginator->shouldReceive('perPage')->andReturn(1);
$paginator->shouldReceive('url')->andReturn('localhost');
$paginator->shouldReceive('count')->andReturn(3);
$paginator->shouldReceive('appends')->andReturn([['foo' => 'bar']]);

$response = new ResponseFake(new Manager());

Expand Down

0 comments on commit 74d0641

Please sign in to comment.