Our first step should be

DB::connection()->enableQueryLog();

After our query it should be placed

$querylog = DB::getQueryLog();

After that it shou;ld be placed

dd($querylog)

BY Best Interview Question ON 17 Mar 2020

Example

DB::connection()->enableQueryLog();

$result = User:where(['status' => 1])->get();

$log = DB::getQueryLog();

dd($log);