Laravel 打印SQL
打印SQL默认是关闭的,需要在/vendor/laravel/framework/src/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(); dd($log); }
如果不想开启但需要临时查看,可以这样操作:
public function index() { DB::connection()->enableQueryLog(); // 需要加多这行 $result = DB::select('select * from activity'); $log = DB::getQueryLog(); dd($log); }
你的坚持 ------ 终将美好 ~

浙公网安备 33010602011771号