Laravel Multiple Pagination in one page

后端 未结 10 1743
独厮守ぢ
独厮守ぢ 2020-11-27 16:15

I\'m having some trouble with my pagination. I\'m having two tables with data from a database and I paginated it with laravel Paginator.

Now my problem is when you g

10条回答
  •  眼角桃花
    2020-11-27 17:01

    This is an easy solution I've found on Laravel 4.

    Controller

    Change the page name before you make the paginator:

    Paginator::setPageName('page_a');
    $collection_A = ModelA::paginate(10);
    
    Paginator::setPageName('page_b');
    $collection_B = ModelB::paginate(10);
    

    View

    Do the same: change the page name before you print the links

    Paginator::setPageName('page_a');
    $collection_A->links();
    
    Paginator::setPageName('page_b');
    $collection_B->links();
    

    If you don't want to lose any page state while you navigate to another page, append to the links the current page from all collections:

    Paginator::setPageName('page_a');
    $collection_A->appends('page_b', Input::get('page_b',1))->links();
    
    Paginator::setPageName('page_b');
    $collection_B->appends('page_a', Input::get('page_a',1))->links();
    

提交回复
热议问题