Skip to content

Commit

Permalink
Fixed bug that LengthAwarePaginator::addQuery() cannot support arra…
Browse files Browse the repository at this point in the history
…y `$values`. (#6900)



Co-authored-by: Deeka Wong <[email protected]>
  • Loading branch information
wuxi889 and huangdijia authored Jun 20, 2024
1 parent b717e59 commit faad00e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function fragment(?string $fragment = null)
*
* @param null|array|string $key
*/
public function appends($key, ?string $value = null): static
public function appends($key, null|array|string $value = null): static
{
if (is_null($key)) {
return $this;
Expand Down Expand Up @@ -471,7 +471,7 @@ protected function appendArray(array $keys): static
/**
* Add a query string value to the paginator.
*/
protected function addQuery(string $key, string $value): static
protected function addQuery(string $key, array|string $value): static
{
if ($key !== $this->pageName) {
$this->query[$key] = $value;
Expand Down
12 changes: 12 additions & 0 deletions tests/LengthAwarePaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public function testAppends()
$paginator = new LengthAwarePaginator([1, 2], 10, 2, 2);
$paginator = $paginator->appends('keyword', 'Hyperf');
$this->assertSame('/?keyword=Hyperf&page=1', $paginator->url(1));

$paginator = new LengthAwarePaginator([1, 2], 10, 2, 2);
$paginator = $paginator->appends('frameworks', []);
$this->assertSame('/?page=1', $paginator->url(1));

$paginator = new LengthAwarePaginator([1, 2], 10, 2, 2);
$paginator = $paginator->appends('frameworks', ['Hyperf', 'Laravel']);
$this->assertSame('/?frameworks%5B0%5D=Hyperf&frameworks%5B1%5D=Laravel&page=1', $paginator->url(1));

$paginator = new LengthAwarePaginator([1, 2], 10, 2, 2);
$paginator = $paginator->appends('settings', ['id' => '1', 'name' => 'Hyperf']);
$this->assertSame('/?settings%5Bid%5D=1&settings%5Bname%5D=Hyperf&page=1', $paginator->url(1));
}

public function testToArray()
Expand Down

0 comments on commit faad00e

Please sign in to comment.