Skip to content

Instantly share code, notes, and snippets.

@rogervila
Last active April 7, 2020 18:44
Show Gist options
  • Save rogervila/99c4da0caff642e03918131d79953736 to your computer and use it in GitHub Desktop.
Save rogervila/99c4da0caff642e03918131d79953736 to your computer and use it in GitHub Desktop.
Laravel query debugger
<?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