Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Phaseolies/Utilities/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function previousPageUrl(): ?string
return null;
}

$queryParams = request()->except('page');
$queryParams = request()->query();
unset($queryParams['page']);

return $this->appendQueryParameters($this->data['previous_page_url'], $queryParams);
}
Expand All @@ -78,7 +79,8 @@ public function nextPageUrl(): ?string
return null;
}

$queryParams = request()->except('page');
$queryParams = request()->query();
unset($queryParams['page']);

return $this->appendQueryParameters($this->data['next_page_url'], $queryParams);
}
Expand Down Expand Up @@ -106,7 +108,7 @@ public function lastPage(): int
/**
* Generate an array of page numbers with ellipsis for gaps
*
* @return string|null
* @return array
*/
public function jump(): array
{
Expand Down
9 changes: 9 additions & 0 deletions tests/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public function testNextPageUrl()
$this->assertNull($lastPagePaginator->nextPageUrl());
}

public function testPreviousAndNextUrlsIgnoreMergedRequestInput()
{
// Input merged in code is server-side data, not part of the query string
request()->merge(['global_merge_testing_data' => 'doppar']);

$this->assertEquals('http://example.com?page=4', $this->paginator->previousPageUrl());
$this->assertEquals('http://example.com?page=6', $this->paginator->nextPageUrl());
}

public function testCurrentPage()
{
$this->assertEquals(5, $this->paginator->currentPage());
Expand Down
Loading