Home >Backend Development >PHP Tutorial >DB::getQueryLog() Returns Empty Array: How to Enable Query Logging in Laravel 5?
DB::getQueryLog() Returns Empty Array: How to Enable Query Logging in Laravel 5
When attempting to view query logs using DB::getQueryLog(), you may encounter an empty result array. This is due to query logging being disabled by default in Laravel 5.
To resolve this issue, you must first enable query logging by calling:
DB::enableQueryLog();
Alternatively, you can register an event listener as follows:
DB::listen( function ($sql, $bindings, $time) { // Perform necessary actions based on the query information } );
Once enabled, you can retrieve the query log using DB::getQueryLog().
Tips:
References:
The above is the detailed content of DB::getQueryLog() Returns Empty Array: How to Enable Query Logging in Laravel 5?. For more information, please follow other related articles on the PHP Chinese website!