// Bad: N+1 problem (executes N+1 queries) $posts = App\Models\Post::all(); foreach ($posts as $post) { echo $post->user->name; // Each access triggers a new query } // Good: Eager loading with `with()` (executes 2 queries) $postsWithUsers = App\Models\Post::with('user')->get(); foreach ($postsWithUsers as $post) { echo $post->user->name; // User is already loaded } // Eager loading multiple relationships $orders = App\Models\Order::with(['customer', 'items', 'items.product'])->get(); // Eager loading with constraints $postsWithComments = App\Models\Post::with(['comments' => function ($query) { $query->where('approved', true); }])->get();