2016-02-27 169 views
0

從5.1升級到5.2後,我的一些頁面出現這個錯誤。我不確定是什麼原因造成的?升級到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); 

    }); 

回答

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); 

    }); 

找到了解決辦法。顯然你需要傳入一個對象,而不是之前使用的那3個參數。

相關問題