//function //laravel 官⽅打印sql
public static function printAllSql(){ DB::listen(function($query) { $sql_arr = [];
$bindings = $query->bindings; $sql = $query->sql;
foreach ($bindings as $replace){
$value = is_numeric($replace) ? $replace : \"'\".$replace.\"'\"; $sql = preg_replace('/\\?/', $value, $sql, 1); }
$sql_arr[] = $sql; print_r($sql_arr); }); }
//调⽤⽅式:直接在请求流的最上⾯调⽤⽅法即可printAllSql();
第⼆种:
DB::connection()->enableQueryLog();#开启执⾏⽇志
$result = DB::table('advert')->whereJsonContains('tag',\"1\")->get();dd(DB::getQueryLog());
因篇幅问题不能全部显示,请点此查看更多更全内容