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

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

http://laravel.com/docs/eloquent#eager-loading

Example:

$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.
0

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.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.