pbelyaev's avatar

Pagination custom page urls

By default Laravel offers urls like this /users?page=2. This is pretty cool, but I want it to be like this /users/page/2. Also, I want to throw 404 when the page is out of pages range. Is there any package that does the trick or any elegant solution?

0 likes
2 replies
MWDeveloper's avatar

@PBELYAEV according to the style of the URL it could not be fixed while if you want to check if the page is out of pages range you have to take a look at this:

https://laravel.com/docs/5.3/pagination#converting-results-to-json

in your case you should convert the result to json and then use the property "last_page" and check.

here is another conversation where pretty much similar to yours it might helps: https://laracasts.com/discuss/channels/laravel/title-pagination-page-number?page=1#reply-305238

pbelyaev's avatar
pbelyaev
OP
Best Answer
Level 3

I've already knew that I can implement whatever I want using plain data but I want some elegant solution. I guess there's only one way to solve the problem. And the way is to create a new package which will do the trick behind the scene.

Please or to participate in this conversation.