How to force eager load in Laravel
Categorized as Laravel
You can force your app to eager load in Laravel using this method in the Service Provider.
This code will throw an exception if you don’t eager load a relationship (except in production).
// app/Providers/AppServiceProvider.php
use Illuminate\Database\Eloquent\Model;
public function boot()
{
Model::preventLazyLoading(
!$this->app->isProduction()
);
}