Eager Loading in Laravel enables you to preload related data for models to minimize database searches. This minimizes the number of queries processed and avoids the N+1 query problem.
Eager Loading is a feature of Eloquent ORM that was created to improve database interactions by fetching related data in advance.
Eager load a relationship:
$posts = Post::with('comments')->get();
Apply conditions to the relationship:
$posts = Post::with(['comments' => function ($query) {
$query->where('approved', true);
}])->get();