标题说我想知道是否有办法让getQueryLog
函数显示查询行。
var_dump(DB::getQueryLog())
答案 0 :(得分:7)
您无法使用getQueryLog()
执行此操作,但您可以收听查询,生成回溯并最终提取行号:
// routes.php
Event::listen('illuminate.query', function($query,$binding,$time,$connections){
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($backtrace as $trace) {
if(array_key_exists('file',$trace) && array_key_exists('line',$trace)){
if( strpos($trace['file'],base_path().'/app') !== false ){
var_dump(array(
'query' => $query
,'binding' => $binding
,'time' => $time
,'connection' => $connections
,'file' => $trace['file']
,'line' => $trace['line']
));
break;
}
}
}
});