从5.1升级到5.2后,我在某些网页上收到此错误。我不确定是什么原因造成的?
ErrorException in RouteServiceProvider.php line 29: Missing argument 2 for App\Providers\RouteServiceProvider::App\Providers{closure}()
当我尝试登录时会发生这种情况。
有什么想法吗?
来自筹码:
1. in RouteServiceProvider.php line 29
2. at HandleExceptions->handleError('2', 'Missing argument 2 for App\Providers\RouteServiceProvider::App\Providers{closure}()', 'Z:\development\wamp\www\larabook\Laravel\app\Providers\RouteServiceProvider.php', '29', array('sql' => object(QueryExecuted))) in RouteServiceProvider.php line 29
3. at RouteServiceProvider->App\Providers{closure}(object(QueryExecuted))
4. at call_user_func_array(object(Closure), array(object(QueryExecuted))) in Dispatcher.php line 221
5. at Dispatcher->fire(object(QueryExecuted)) in Connection.php line 750
RouteServiceProvider.php中的第29行(下面的第一行):
\DB::listen(function($sql,$bindings,$time) {
$sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
$sql = vsprintf($sql, $bindings);
$time_now = (new \DateTime)->format('Y-m-d H:i:s');;
$log = $time_now.' | '.$sql.' | '.$time.'ms'.PHP_EOL;
\Storage::append('logs\query.log', $log);
});
答案 0 :(得分:1)
\DB::listen(function($query) {
$sql = str_replace(array('%', '?'), array('%%', '%s'), $query->sql);
$sql = vsprintf($sql, $query->bindings);
$time_now = (new \DateTime)->format('Y-m-d H:i:s');;
$log = $time_now.' | '.$sql.' | '.$query->time.'ms'.PHP_EOL;
\Storage::append('logs\query.log', $log);
});
找到解决方案。显然你现在需要传入一个对象,而不是我之前使用的那三个参数。