Created
November 21, 2017 15:07
-
-
Save mathieutu/0d0063166f4ced6ec06e8c62c5037442 to your computer and use it in GitHub Desktop.
Dump all sql queries in Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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