为了方便调试,开发时需要打印sql。


 

方法一(全局打开):

SQL打印默认是关闭的,

需要在/vendor/illuminate/database/Connection.php中打开。

protected $loggingQueries = true;

然后使用方法:

$result = DB::table('user')->get();
$log = DB::getQueryLog();
dd($log);

方法二(临时打开):

DB::connection()->enableQueryLog();
$result = DB::table('user')->get();
$log = DB::getQueryLog();
dd($log);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-01-02
  • 2021-09-15
猜你喜欢
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案