Created
May 25, 2023 09:24
-
-
Save chimit/aeb9019984659d472b319fd886c121cd to your computer and use it in GitHub Desktop.
Output all SQL queries in Laravel
This file contains hidden or 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 | |
// Debug SQL queries | |
// Put anywhere, e.g. in routes/api.php | |
if (config('app.debug')) { | |
\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) { | |
echo 'Query: '.$query->sql."\n\n"; | |
echo 'Bindings: '.var_export($query->bindings, true)."\n\n"; | |
echo 'Time: '.$query->time."\n\n"; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment