laravel db enable query log code example

Example 1: How to Log Query in Laravel

DB::enableQueryLog();
$arr_user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());

Example 2: How to Log Query in Laravel

DB::enableQueryLog();
$user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());

Example 3: eloquent get query log

DB::connection()->enableQueryLog(); //enable query log
 $data = $order->all(); //query execute
 $queries = DB::getQueryLog(); //get query
 return dd($queries); //show query

Tags:

Php Example