Skip to content

Instantly share code, notes, and snippets.

@mayanksdudakiya
Created May 31, 2023 13:37
Show Gist options
  • Save mayanksdudakiya/8d38ccd780fcd7dfc8cb3ebb8e315902 to your computer and use it in GitHub Desktop.
Save mayanksdudakiya/8d38ccd780fcd7dfc8cb3ebb8e315902 to your computer and use it in GitHub Desktop.
Prevent lazy loading in Laravel and check for N+1 queries being fired in your App so that you can solve it
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot()
{
Model::preventLazyLoading(! app()->isProduction());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment