兩種方法
第一種方法:
打印SQL默認是關閉的,需要在/vendor/illuminate/database/Connection.php中打開。
/** * Indicates whether queries are being logged. * * @var bool */ // protected $loggingQueries = false; protected $loggingQueries = true;
之后可在代碼中使用了:
public function index(){ $result = DB::select('select * from activity'); $log = DB::getQueryLog(); var_dump($log); }
第二種方法:
如果不想開啟但需要臨時查看,可以這樣操作:
public function index(){ DB::connection()->enableQueryLog(); $result = DB::select('select * from activity'); $log = DB::getQueryLog(); var_dump($log); }