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

kapitan's avatar

Custom Pagination Name Using Repository Pattern

I have something like these:

$order_blue = $this->orderRepository->findWhere(['color' => 'blue'])->paginate(5);

$order_red = $this->orderRepository->findWhere(['color' => 'red'])->paginate(5);

then i need to display them on the same window / blade on a separate html tables.

my problem is, if I'll click the page 3, the other table also respond.

my second question is, the two tables on display has a search box each, how can i construct the code on my controller to respond on the search boxes individually.

thank you very much in advance!

0 likes
4 replies
kapitan's avatar

thank you for your reply.

yeah, i tried this:

$order_red = $this->orderRepository->findWhere(['color' => 'red'])->paginate(5,['*'],'page_red');

and it is not working.

it says:

Call to undefined method Illuminate\Database\Query\Builder::page_red()

i tried to add:

use Illuminate\Database\Query\Builder;

use Illuminate\Contracts\Pagination\LengthAwarePaginator;

at the top, but i got the same error message.

anything im missing?

jlrdw's avatar

The LengthAwarePaginator works a little different than just paginate(5)

I did a guide on it a while back

https://laracasts.com/discuss/channels/tips/length-aware-paginator

and another article

https://christophersax.com/2016/custom-lengthawarepaginator-in-laravel/

my second question is, the two tables on display has a search box each, how can i construct the code on my controller to respond on the search boxes individually.

Jquery ajax could be used with results in a div, but gets a little more complex. You should take several tutorials on this before attempting.

In this video https://drive.google.com/file/d/0B1_PFw--3o74TC16eXRBYXZBNFk/view

I am working in divisions that have display:none until needed, then display:block

Ajax pagination can also be done in div's.

1 like
kapitan's avatar

didnt use repository pattern, just used Model::paginate(5,['*'],'page_red') and i was able to create page names for my tables. problem solved. thanks to all.

Please or to participate in this conversation.