use App\Models\Post; use App\Models\User; // Eager load 'comments' relationship, but only approved comments $postsWithApprovedComments = Post::with(['comments' => function ($query) { $query->where('is_approved', true); }])->get(); // Eager load 'users' and their 'posts', but only posts published after a certain date $usersWithRecentPosts = User::with(['posts' => function ($query) { $query->where('published_at', '>', '2023-01-01'); }])->get();