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 onLastPage method to the Paginator #40265

Merged
merged 3 commits into from
Jan 5, 2022

Conversation

johanvanhelden
Copy link
Contributor

@johanvanhelden johanvanhelden commented Jan 5, 2022

In short:
This PR adds a convenience method to the paginator to determine if we are on the last page.

Why:
There is a useful onFirstPage method but it lacks the opposite onLastPage method.

I was just writing some blade code for a Tailwind pagination component and without reading a any documentation onFirstPage worked.

Meaning, you can have the following code:

@if ($paginator->onFirstPage())

But for the last page, you need to call an unexpected hasMorePages method and reverse the logic, so it becomes:

@if (!$paginator->hasMorePages())

So not only did I encounter a blade error, because onLastPage did not exist, but also I had to reverse the logic.

This PR keeps things consistent by adding a onLastPage() so you can simple do:

@if ($paginator->onLastPage())

Which, in my mind, is a very logical thing to try after using onFirstPage without reading any documentation.

@johanvanhelden johanvanhelden marked this pull request as ready for review January 5, 2022 15:00
@taylorotwell taylorotwell merged commit f825fbb into laravel:8.x Jan 5, 2022
@taylorotwell
Copy link
Member

Thanks for contributing to Laravel! ❤️

@johanvanhelden johanvanhelden deleted the add-on-last-page-method branch January 5, 2022 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants