流明

2016-03-01 75 views
0

刀片模板使用$錯誤,我有一段簡單的代碼,我想在刀片模板中使用:流明

@if($errors->has()) 
     @foreach ($errors->all() as $error) 
      <div>{{ $error }}</div> 
    @endforeach 
@endif 

但是爲了使用$錯誤,我讀的地方,我需要使用web中間件,所以我設置以及對路線:

'middleware' => ['web'] 

並補充說:

$app->register(Illuminate\Session\Middleware\StartSession::class); 
$app->register(Illuminate\View\Middleware\ShareErrorsFromSession::class); 

到app.php

但現在,當我打開這條路,我得到這個錯誤:

lumen.ERROR: exception 'ErrorException' with message 'Argument 1 passed to Illuminate\Session\Middleware\StartSession::__construct() must be an instance of Illuminate\Session\SessionManager, instance of Laravel\Lumen\Application given 
+0

你在使用laravel 5.2嗎? – Latheesan

+0

可能的重複:http://stackoverflow.com/questions/34438463/laravel-5-2-errors-not-appearing-in-blade – Latheesan

+0

它是5.1.I試圖遵循鏈接線程的一些答案,似乎錯誤消失了,但是當我嘗試訪問視圖中的$錯誤時,我得到'exception'ErrorException'消息'Undefined variable:errors'',這就像中間件根本不包含在內。 – Zed

回答

0

的解決方案是增加這app.php:

$app->middleware([ 
      Illuminate\Session\Middleware\StartSession::class,       
      Illuminate\View\Middleware\ShareErrorsFromSession::class 
]);