Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add missing onLastPage to CursorPaginator #42299

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions src/Illuminate/Pagination/CursorPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ public function onFirstPage()
return is_null($this->cursor) || ($this->cursor->pointsToPreviousItems() && ! $this->hasMore);
}

/**
* Determine if the paginator is on the last page.
*
* @return bool
*/
public function onLastPage()
{
return ! $this->hasMorePages();
}

/**
* Get the instance as an array.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Pagination/CursorPaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ public function testCanTransformPaginatorItems()
$this->assertSame([['id' => 6], ['id' => 7]], $p->items());
}

public function testLengthAwarePaginatorisOnFirstAndLastPage()
{
$paginator = new CursorPaginator([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]], 2, null, [
'parameters' => ['id'],
]);

$this->assertTrue($paginator->onFirstPage());
$this->assertFalse($paginator->onLastPage());

$cursor = new Cursor(['id' => 3]);
$paginator = new CursorPaginator([['id' => 3], ['id' => 4]], 2, $cursor, [
'parameters' => ['id'],
]);

$this->assertFalse($paginator->onFirstPage());
$this->assertTrue($paginator->onLastPage());
}

protected function getCursor($params, $isNext = true)
{
return (new Cursor($params, $isNext))->encode();
Expand Down