Lazy loading is convenient because you don’t have to think upfront about which relationships to select from the database. Laravel’s Eloquent models are an implementation of the active record pattern, where each instance of a model is backed by a row in the database. If you access an attribute that was not selected, Laravel simply returns null. Your code will think an attribute is null. It might not be null at all.
Table of contents
N+1 prevention #Partially hydrated model protection #Attribute typos and renamed columns #Mass assignment protection #Model strictness #Polymorphic mapping enforcement #Preventing stray HTTP requests #Long-running event monitoring #Make the implicit explicit #Want a powerful and performant database that doesn’t slow you down?Sort: