iGenezys's avatar

Multiple Pagination

Hi people.

I saw the subject a lot of times but it didn"t satisfied me, so I'm asking here.

I need to do a multiple pagination on a page. In this page I have two lists and need to have my pagination on each lists.

Actually I did this in the controller :


public function getDev(){
        $devs = Developpement::where('id_categorie', 1)->paginate(1, ['*'], 'dev');
        $templates = Developpement::where('id_categorie', 2)->paginate(1, ['*'], 'template');

        return view('main.developpement', compact('devs', 'templates'));
    }

And my view just have the {{ $templates->links() }} and {{ $devs->links() }}

Actually the result is that I when I click on my first pagination, everything is correct and the second is fine too. But when I click on the second, It reset the first. The URL stay like :

http://localhost:8888/tloading/developpement?template=2

I'd like to have an URL like http://localhost:8888/tloading/developpement?template=2&devs=2

How could I do this ?

Thank You !

0 likes
6 replies
bobbybouwmann's avatar
Level 88

Yeah so that happens automatically because your ->links() don't know anything from the other pagainations right?

I believe you can fix it by doing something like this

{{ $devs->appends(['template' => request('template', 1)])->links() }}
{{ $templates->appends(['dev' => request('dev', 1)])->links() }}

Note: I didn't tested this, but it should put you in the right direction!

Snapey's avatar

In both links you need to append the page number of the other paginator

templates appends() devs

devs appends() templates

Snapey's avatar

bum. bb posted at the same time.

I would put the appends in the controller rather than the view

iGenezys's avatar

It's perfect, thank you !

Just asking @Snapey , how could I put this in the controller ? Like this ?


$devs->appends(['template' => request('template', 1)]);
$templates->appends(['dev' => request('dev', 1)]);

then keep de $devs->links()in the view ?

Feels like it's working, but I prefer asking and be sure !

Thank you anyway !

Please or to participate in this conversation.