md_imran's avatar

How to get pagination with groupBy in eloquent?

Dear, I have a query like this - return $query->get()->groupBy('date');

It works fine but I want to add pagination on it, while I use- return $query->get()->groupBy('date')->paginate(10) , it does not working. can anyone suggest how to make it okey?

0 likes
6 replies
Tray2's avatar

Try removing the get(), the paginate() does the same thing a get but instead of getting all the records it paginates them.

md_imran's avatar

@Tray2 get() does not work with groupBy, ensure of that pls.

I found forPage can resolve the need.

anyway, Thanks Sir :P

Sinnbeck's avatar

You need to do the groupBy in the query. But what is the expected result?

1 like

Please or to participate in this conversation.