Eager Loading And Lazy Loading

Eager Loading :

Eager loading helps you to load all your entities at once.

The related objects[child objects] will loaded automatically with parent objects.

when to use eager loading

user eager loading when the relations are not too much .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 lazy loading related objects [child-objects] are not loading with parent objects. until they are requested.

by default laravel eloquent supports lazy loading

when to use lazy loading :

when you are using one to many collections

when you are sure that you are not using related entities instantly