They amount to the same thing (assuming you mean lazy eager loading); same number of queries, same PHP workload to set the relations on the various models. It makes sense to eager-load if your logic branches where those additional relations are needed on one path, but not on another; in either case the parent model(s) are needed and perhaps already fetched in that request.
lazy loading is better than eager loading?
Please help me to better understand.
Eager Loading: Eager Loading helps you to load all your needed entities at once. i.e. related objects (child objects) are loaded automatically with its parent object.
When to use:
Use Eager Loading when the relations are not too much. Thus, Eager Loading is a good practice to reduce further queries on the Server.
Use Eager Loading when you are sure that you will be using related entities with the main entity everywhere.
Lazy Loading: In case of lazy loading, related objects (child objects) are not loaded automatically with its parent object until they are requested. By default LINQ supports lazy loading.
When to use:
Use Lazy Loading when you are using one-to-many collections.
Use Lazy Loading when you are sure that you are not using related entities instantly.
Do you mean lazy collections?
They both do the same thing. Alleviate the N + 1 query problem.
If the parent model has already been retrieved use load.
public function show(Post $post)
{
$post->load('comments.user');
return view('posts.show', compact('post'));
}
If you make a new query use with.
public function show($id)
{
$post = Post::with('comments.user')->findOrFail($id);
return view('posts.show', compact('post'));
}
Look at it like an invoice. This one is for spays and neuters
It's the invoice id that relates the parent and child, you do not need a customer on the "line items".
https://i.imgur.com/7l7DaPM.jpg

- Parent = the invoice
- child = the spays or neuters in this case (I call line items)
A one to many including eloquent is two queries, one for parent, another for child.
At times you need to paginate child if a lot of "line items"
And above was just quick rough draft.
Try not to get lost in terms, Just learn how to write efficient sql queries.
And as mentioned watch out for the n + 1 problem, which @jeffreyway explains in one of his videos. I don't recall which one.
Edit: Found reference in docs https://laravel.com/docs/7.x/eloquent-relationships#eager-loading
Please or to participate in this conversation.