Saturday, March 17, 2018

Laravel - Code Tips

To Log all queries executed by Eloquent:
Add the below code snippet into AppServiceProvider boot() method.

\Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
            \Illuminate\Support\Facades\Log::info($query->sql);
            \Illuminate\Support\Facades\Log::info($query->bindings);
            \Illuminate\Support\Facades\Log::info($query->time);
        });

\DB::listen(function($sql, $bindings, $time) {
            Log::info($sql);
            Log::info($bindings);
            Log::info($time);
        });



No comments:

Post a Comment