Log all the database queries during development

If you want to log all the database queries during development add this snippet to your AppServiceProvider

1public function boot()
2{
3 if (App::environment('local')) {
4 DB::listen(function ($query) {
5 logger(Str::replaceArray('?', $query->bindings, $query->sql));
6 });
7 }
8}

Tip given by @mmartin_joo

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord