Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GianniGianni's avatar

Custom pagination URL

With the default laravel pagination my url looks like

mydomain.com/item?page=2

Is there a way to obtain something like

mydomain.com/item/2 or mydomain.com/item/page/2

Thanks :)

0 likes
10 replies
headersalreadysent's avatar

A paginator class (Illuminate\Pagination\Paginator) has a setBaseUrl method.

But i didn't tested and i dont think it can be use to transform page numbers, from query string to url segment.

bashy's avatar

As long as you can pick up on those IDs at the end, because I know Route::resource() would have issues with that URI structure.

GianniGianni's avatar

@bashy What do you mean exactly?

I need to do something similar to the episode mechanism here in Laracasts.

When I click on an episode (belonging to a serie) the url looks like

https://laracasts.com/series/SERIE_TITLE/episodes/2

Where 2 means the second episode of that serie (2 is not the id of the episode)

At first I tought to use pagination to easily have next and prev. buttons by default, but now I have to think something else.

What may I do?

bashy's avatar

Personally, I wouldn't bother changing it. What's wrong with "?page=#"? To me episodes/2 would look like episode 2

1 like
GianniGianni's avatar

@bashy My previous post was not clear, sorry.

my goal is to implement something like episodes in laracasts. I don't need pagination. I tought to use pagination (with 1 element per page) just to have next and prev buttons out of the box! It was a trick!

Now I realized it can't work because of the url format

Is there antother way to do something similar (with or without pagination)?

bashy's avatar

Okay, I see. Why not get that from a database field in the pivot or something?

GianniGianni's avatar

@bashy Because If I want to add an episode in the middle of the serie I'll have to change all the following entries

@zofe I'll try this

bashy's avatar

But you're talking about episode IDs (like a series on here), if you add one in the middle, you will have to edit the others (or make a query to update everything to the right by one).

Some ordering/sorting functions do that.

kornel's avatar

There are issues with SEO because of the ?page=

Please or to participate in this conversation.