Laravel Multiple Pagination in One Page

Laravel Multiple Pagination in one page

Unfortunately I can't test this code right now, but browsing at the docs and the code (in Illuminate/Pagination/Environment) I guess you could something like this:

# use default 'page' for this
$collection1 = Model::paginate(20);

# use custom 'other_page' for this
$collection2 = Model2::paginate(20);

The setPageName() method isn't documented in the docs, but it's a public method alongside those indicated in the documentation, so it should be working fine. FOr reference, this is the declaration (l. 171-180 in vendor/laravel/framework/src/Illuminate/Pagination/Environment.php):

* Set the input page parameter name used by the paginator.
* @param string $pageName
* @return void
public function setPageName($pageName)
$this->pageName = $pageName;

Now take into consideration that you will have another query string appended to the url, so you need to tell the pagination to consider it. Use the appends() method:

$collection1->appends(array_except(Request::query(), 'page'))->links();

$collection2->appends(array_except(Request::query(), 'other_page'))->links();

That is, tell each Presenter to build up the url with all the query strings (the array resulting from Request::query() without the current index used by the paginator, or you'll end up with a double value). array_except() is a Laravel built in array helper that returns the given array (1st parameter) purged of the passed index (2nd parameter).

I'll try to test this code as soon as I can, but it should work. Let me know in any case!

Laravel 6 multiple pagination in one page

This should be possible as long as you keep track of the page value for the opposite set:

{{$infos->appends(['info' => $infos->currentPage(), 'berita' => $beritas->currentPage()])->links()}}

{{$beritas->appends(['berita' => $beritas->currentPage(), 'info' => $infos->currentPage()])->links()}}

I'll try and test this theory out later if I find time.

How to implement multiple pagination in single page | laravel 5.7

Yes its because by default pagination url with page

To Change just pass few extra parametes to paginate method


return view('index',['products' => $products, 'users' => $users ]);


return view('index',['products' => $products, 'users' => $users ]);

Laravel 5 multiple pagination in a single page

If you see in the laravel core, then you will see paginate function something like this

* Paginate the given query.
* @param int $perPage
* @param array $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
* @throws \InvalidArgumentException
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
$total = $this->query->getCountForPagination();
$page = $page ?: Paginator::resolveCurrentPage($pageName),
$perPage = $perPage ?: $this->model->getPerPage()
return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,

Now in above function you can pass $pagename to make both pagination working separately like below

$collectionA = ModelA::paginate(4, ['*'], 'pagination_a');
$collectionB = ModelB::paginate(4, ['*'], 'pagination_b');

Or You can also use setPageName function for this

Multiple Laravel 5 Paginations within the same page

If you look at the paginate method:

You see that it accepts a $pageName variable, which tells it which request variable to use.

So you can do this:

MyModel::where(...)->paginate(20, ['*'], 'fooPage');

And Laravel will use $request->fooPage for the page variable.

Or, you can see the paginate method also allows you to just explicitly pass in the page variable itself as the fourth parameter:

MyModel::where(...)->paginate(20, ['*'], null, $request->myPageVar);

And now a GET variable ?myPageVar=1 will set the page.

Related Topics

Leave a reply