From 74d0641e09c57ff30436cb17c3e8176c7ad7363b Mon Sep 17 00:00:00 2001 From: Steven Richardson Date: Thu, 14 Jul 2016 13:33:35 +0100 Subject: [PATCH] IMPROVEMENT Add existing query params to pagination links (#30) * Add existing query params to pagingation links * Add appends method to mock object for passing tests --- src/Laravel/Response.php | 3 +++ tests/Laravel/ResponseTest.php | 1 + 2 files changed, 4 insertions(+) diff --git a/src/Laravel/Response.php b/src/Laravel/Response.php index 14d6b45..d58575f 100644 --- a/src/Laravel/Response.php +++ b/src/Laravel/Response.php @@ -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)); diff --git a/tests/Laravel/ResponseTest.php b/tests/Laravel/ResponseTest.php index 1248d5b..b530781 100644 --- a/tests/Laravel/ResponseTest.php +++ b/tests/Laravel/ResponseTest.php @@ -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());