Skip to content

Instantly share code, notes, and snippets.

@Grafikart
Created August 25, 2022 08:07
Show Gist options
  • Save Grafikart/c82c3d678613374815c5f1fbe1d20fb4 to your computer and use it in GitHub Desktop.
Save Grafikart/c82c3d678613374815c5f1fbe1d20fb4 to your computer and use it in GitHub Desktop.
Laravel SQL Log
<?php
// Ajouter ce code dans boot()
if ($this->app->isLocal() && ($_SERVER['PHP_SELF'] ?? null) !== 'artisan') {
$k = 0;
\Illuminate\Support\Facades\DB::listen(function (\Illuminate\Database\Events\QueryExecuted $q) use (&$k) {
$k++;
file_put_contents('php://stdout', "[{$k}] \e[34m{$q->sql}\t\e[37m]".json_encode($q->bindings)."\t\e[32m{$q->time}ms\e[0m\n");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment