Skip to content

Instantly share code, notes, and snippets.

@mathieutu
Created November 21, 2017 15:07
Show Gist options
  • Save mathieutu/0d0063166f4ced6ec06e8c62c5037442 to your computer and use it in GitHub Desktop.
Save mathieutu/0d0063166f4ced6ec06e8c62c5037442 to your computer and use it in GitHub Desktop.
Dump all sql queries in Laravel
<?php
// \App\Providers\AppServiceProvider::boot
if ($this->app->runningInConsole() && !$this->app->runningUnitTests()) {
$this->dumpAllSqlQueries();
}
private function dumpAllSqlQueries()
{
DB::listen(function ($query) {
dump(str_replace_array(
$search = '#' . str_random() . '#',
$query->bindings,
preg_replace('/\B\?/', $search, $query->sql))
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment