Laravel – Log All SQL Queries

  • Post category:Snippets

If you want to log all SQL queries to the laravel.log file use the following code in your AppServiceProvider.phpboot() method:

class AppServiceProvider extends ServiceProvider
{
  // ...
  
  public function boot()
    {
        if (App::isLocal()) {
            DB::listen(function ($query) {
            logger(Str::replaceArray('?', $query->bindings, query->sql));
            });
        }
    }
}