Support the ongoing development of →
Database Eloquent
Last updated 2 years ago.

Looks like eager load constraints may be what you are looking for.


$user = User::with(array('posts' => function($query) { $query->whereBetween('created_at',array('2014-02-20 00:00:00','2014-02-21 23:59:59')); }))->find(1);

I was not able to test the code but hope this helps point you in the right direction.

Last updated 2 years ago.

thank you michaeldeol, but with your solution, only get the users with posts between dates, and i need get all users.

I forgot the parenthesis, with $user->posts()->where........

it works!!!

Thank you!!

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.