Sunday, March 26, 2017

Laravel 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);
        });