Laravel Pro Tips
🚀If performance is the #1 priority in your project you might want to disable lazy loading completely.
Eloquent will throw a huge exception in your face if a relation is not eager-loaded and you try to access it.
Just use this snippet:
🔥 #Laravel Tip: Protect your database from the dangers of lazy loading by disabling it in your Laravel app. You can also customise how violations are handled, which is perfect for models outside of your control e.g. within packages.
3️⃣ You can enable or disable lazy loading for a model using $preventsLazyLoading
Marian Pop 🇺🇦 Laravel Magazine
No articles were found.