intermediateLaravel
Previous
What is the difference between eager loading and lazy loading?
Next
What are Eloquent API resources?
What is the difference between with(), load(), and loadMissing()?
Answer
Clear, interview-ready explanation
with() is called while building the initial Eloquent query, so it eager loads relationships as the models are retrieved. It is the usual choice when the required relationships are known before the primary query is executed.
load() performs lazy eager loading on a model or collection that has already been retrieved and will load or reload the specified relationships. loadMissing() also works after retrieval, but it loads only relationships that are not already loaded. Use it when code may receive models in different loading states and should avoid replacing data that is already available.