Last active
April 7, 2020 18:44
-
-
Save rogervila/99c4da0caff642e03918131d79953736 to your computer and use it in GitHub Desktop.
Laravel query debugger
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 | |
/** | |
* Original: https://github.com/morrislaptop/laravel-query-builder-dump/blob/master/src/QueryBuilderDumpServiceProvider.php | |
*/ | |
if (app()->environment() != 'production') { | |
\DB::listen(function ($executed) { | |
$flat = \Arr::flatten($executed->bindings); | |
foreach ($flat as $binding) { | |
$binded = $binding instanceof \DateTime ? $binding->format('Y-m-d H:i:s') : $binding; | |
$binded = is_numeric($binded) ? $binded : "'{$binded}'"; | |
$executed->sql = preg_replace('/\?/', $binded, $executed->sql, 1); | |
} | |
\Log::info($executed->sql); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment