There are actually examples in the chapter on relationships.
Jan 12, 2021
7
Level 2
Query building with Eloquent Models
How do I build the below query with Eloquent Models?
select users.*, posts.* from users, posts where users.id = 1 and users.id = posts.user_id and posts.status = 'draft'
Level 75
auth()->user()->load(['posts' => function ($query) {
$query->where('status', 'draft');
}]);
https://laravel.com/docs/8.x/eloquent-relationships#lazy-eager-loading
1 like
Please or to participate in this conversation.