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

Mfrancik's avatar

Multipal querys on same relationship by date range

Each user has many cases. I want to query so I can display in a forEach loop, cases created today, this week, this month.

Is this possible?

0 likes
1 reply
jekinney's avatar

Yes. What I suggest is get as many cases as you'll need eager loaded. Maybe all, maybe just for the month.

Then with the eloquent collection that's returned manipulate it as you need. This will reduce your queries and is efficient.

I like using laravels collect() for this type of issue. Set each collection to its own variable so you still have the original.

Look at collections in the docs.

https://laravel.com/docs/5.3/collections#method-groupby

Please or to participate in this conversation.