devratna's avatar

Custom Pagination URLs L5

By Default Pagination URLs are show as localhost/something/?page=1 I want to make it like this localhost/something/page/1 Is there anyway to do it like that?

0 likes
8 replies
bobbybouwmann's avatar

Of course there is, but you will need to make your own paginator and you need to handle everything for yourself as well!

Your route might look like this

Route::get('articles/page/{page}, ['uses' => 'ArticlesController@index']);

Now in your controller you get the page number

public function index($page)
{
    // Based on the page you can get all the articles you need
    // I leave that to you how you handle that ;)
}

In your view you have the generate your own links to paginate like this.

What you also can do is create a new Paginator class and for that I recommend you to take a look at how Laravel is doing that ;) The standard used paginator by Laravel is called LengthAwarePaginator if I'm right. This might be a good example for you to create your own ;) You can find the file in vendor\laravel\framework\src\Illuminate\Pagination\LengthAwarePaginator

bobbybouwmann's avatar

Lol? I try to help you out and you just bump the thread? Did you even read anything? Did you even try something? Please don't be lazy!

devratna's avatar
devratna
OP
Best Answer
Level 1

had to code a custom paginator now its all working :)

devratna's avatar

I wanted a real working example not a half answer?

bobbybouwmann's avatar

You can handle that on a better way of course. Show what you have tried? Tell us where you are stuck..

Please or to participate in this conversation.