Skip to content

Commit f825fbb

Browse files
[8.x] Add onLastPage method to the Paginator (#40265)
* Add onLastPage method and add tests * CS tweaks * Trim spaces
1 parent 16359b5 commit f825fbb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Illuminate/Pagination/AbstractPaginator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,16 @@ public function onFirstPage()
379379
return $this->currentPage() <= 1;
380380
}
381381

382+
/**
383+
* Determine if the paginator is on the last page.
384+
*
385+
* @return bool
386+
*/
387+
public function onLastPage()
388+
{
389+
return ! $this->hasMorePages();
390+
}
391+
382392
/**
383393
* Get the current page.
384394
*

tests/Pagination/LengthAwarePaginatorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public function testLengthAwarePaginatorSetCorrectInformationWithNoItems()
5656
$this->assertEmpty($paginator->items());
5757
}
5858

59+
public function testLengthAwarePaginatorisOnFirstAndLastPage()
60+
{
61+
$paginator = new LengthAwarePaginator(['1', '2', '3', '4'], 4, 2, 2);
62+
63+
$this->assertTrue($paginator->onLastPage());
64+
$this->assertFalse($paginator->onFirstPage());
65+
66+
$paginator = new LengthAwarePaginator(['1', '2', '3', '4'], 4, 2, 1);
67+
68+
$this->assertFalse($paginator->onLastPage());
69+
$this->assertTrue($paginator->onFirstPage());
70+
}
71+
5972
public function testLengthAwarePaginatorCanGenerateUrls()
6073
{
6174
$this->p->setPath('http://website.com');

0 commit comments

Comments
 (0)