Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在laravel5中打印mysql查询_Mysql_Laravel 5 - Fatal编程技术网

在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