Laravel 5.3 - How to log all queries on a page?

后端 未结 7 1578
生来不讨喜
生来不讨喜 2020-12-24 12:48

My team and I are working on a rather big project. There\'s queries going on everywhere - in controllers, in view composers in views (lazy loading) and probably in some othe

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 13:38

    Here comes the perfect example:

    https://laravel.com/docs/5.3/database#listening-for-query-events

    Open app\Providers\AppServiceProvider.php and add the following to Boot() function:

    DB::listen(function ($query) {
        var_dump([
            $query->sql,
            $query->bindings,
            $query->time
        ]);
    });
    

提交回复
热议问题