Logging SQL queries in Laravel 5

To create Log entries for every sql query, include the following before the code you need to check. Even drop it into the routes file if you want to log every transaction.

DB::listen(function ($sql) {
        Log::info('Bindings: ' . implode(', ',$sql->bindings));
        Log::info('Last Query took ' . $sql->time . ' seconds');

If including in a controller, you will need to add at the top of the controller

use DB;
use Log;

Leave a comment

Your email address will not be published. Required fields are marked *