Elequent ORM ->toSql() 可以输出sql语句,但如果带 binding 参数的,输出的语句会带?,类似下面这样:
select * from `rooms` where `rooms`.`project_id` = ?
barryvdh/laravel-debugbar 这个包需要添加代码注入配置,仅限浏览器输出,如果是 postman 工具调试,就无法查看输出的SQL了。
简便方法#

可以把下面代码放在查询语句前:
\DB::listen(function($sql, $bindings, $time) {
     foreach ($bindings as $replace){
         $value = is_numeric($replace) ? $replace : "'".$replace."'";
         $sql = preg_replace('/\?/', $value, $sql, 1);
     }
     dd($sql);
 });

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案