Ad

How To Implement Multiple Pagination In Single Page | Laravel 5.7

I have a situation where i want to implement multiple pagination in single page using laravel paginate() function.

code in Controller file.

$products=Product::paginate(10);
$users=Users::paginate(10);
return view('index',['products' => $products, 'users' => $users ]);

code in my view blade file.

{{    $products->links();  }}
{{    $users->links();  }}

Now when I click on user pagination than the product also show from current page only..

I am using laravel 5.7 can someone tell me how can I use multiple paginations in a single page.

Thanks in advance.

Ad

Answer

Yes its because by default pagination url with page

To Change just pass few extra parametes to paginate method

FROM

$products=Product::paginate(10);
$users=Users::paginate(10);
return view('index',['products' => $products, 'users' => $users ]);

TO

$products=Product::paginate(20,['*'],'productPagination');
$users=Users::paginate(20,['*'],'userPagination');
return view('index',['products' => $products, 'users' => $users ]);

And here is the Pagination function

https://github.com/laravel/framework/blob/dfa006b884e4ca2952eeab1af7ecd151c0220db7/src/Illuminate/Database/Eloquent/Builder.php#L742

Hope its helps

Ad
source: stackoverflow.com
Ad