在laravel5中打印mysql查询
我的控制器上有以下代码用于更新记录在laravel5中打印mysql查询,mysql,laravel-5,Mysql,Laravel 5,我的控制器上有以下代码用于更新记录 $inforequest = Info::find($id); $inforequest->infoname = $inforequest->infoname; $inforequest->infotitle = $inforequest->infotitle; $inforequest->infotag = $inforequest->infotag; $inforequest-&g
$inforequest = Info::find($id);
$inforequest->infoname = $inforequest->infoname;
$inforequest->infotitle = $inforequest->infotitle;
$inforequest->infotag = $inforequest->infotag;
$inforequest->infogroup = $inforequest->infogroup;
$last_query = $inforequest->save();
return redirect('auth/getallinfo');
但它没有更新数据,也没有给出任何错误
如何打印mysql查询
提前谢谢 您可以使用toSql()
方法
$inforequest = Info::find($id)->toSql();
dd($inforequest);
为了调查我的查询,我在AppServiceProvider中的boot()函数中放置了数据库的监听器:
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
[...]
DB::listen(function ($query) {
echo '<br>_____________<br>';
var_dump($query->sql);
var_dump(($query->time/1000)." sec");
echo '<br>-------------<br>';
});
}
}
类AppServiceProvider扩展了ServiceProvider
{
公共函数boot()
{
[...]
DB::listen(函数($query){
回音“
”;
变量转储($query->sql);
变量转储(($query->time/1000)。“秒”);
回声'
--------------
';
});
}
}
我曾经打印出查询和查询时间(以秒为单位)。您还可以var_转储整个$query