public function process(Request $request, callable $next) : Response { Db::connection()->listen(function (QueryExecuted $queryExecuted){ dump("[{$queryExecuted->time} ms] {$queryExecuted->sql}"); }); return $next($request); }
每次請求都會多加一條sql
你這樣放到中間件里,每次請求都會重復調(diào)用Db::connection()->listen,所以sql打印會重復。
參考手冊加一個bootstrap,bootstrap只會在啟動時只會執(zhí)行一次,把Db::connection()->listen放在bootstrap里就好了
http://wtbis.cn/doc/webman/others/bootstrap.html
我試試