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

phoennix's avatar

Implementation of multiple pagination on Laravel 7

Hello,

I'm trying to integrate several paginations on Laravel and I encounter a problem. Here is my code:

        $selectedCompanies = $selectedCampaign->companies->paginate(1);
        $selectedCompanies->setPageName('other_page');
        dd($selectedCompanies->currentPage());

If I go to URL/users/ID?other_page=2, I always get 1 on the currentPage. Is this normal ? As a result, I don't have any page change that works at the URL level.

If I haven't been very clear, don't hesitate to let me know :)

Thank you !

0 likes
4 replies
phoennix's avatar

I get an error when I carry out like your article

"Argument 2 passed to Illuminate\Database\Eloquent\Collection::Spatie\CollectionMacros\Macros{closure}() must be of the type string, array given"

$selectedCompanies = $selectedCampaign->companies->paginate(2, ['*'], 'cbShows');

I deliberately didn't change the values in your article while I was doing my tests.

Snapey's avatar

So you are not using the regular paginator?

Spatie\CollectionMacros\Macros{closure}()

jlrdw's avatar

If you are using double pagination like

Remember you have to tell each paginator "where to be" on each click.

I normally only use "double" pagination for things like accounts receivable reports.

I.e., A company showing it's receivables with a next company link and another link showing pagination for the current companies data.

If you need two paginators where the data is not related, you could use ajax and divisions.

And image was just an example for a reply on another post.

You may want to consider refactoring and use @snapey solution, it might be the easiest to achieve.

I haven't searched myself, so I am not sure if @jeffreyway has a video on multiple pagination.

Please or to participate in this conversation.