【发布时间】:2016-03-01 10:21:18
【问题描述】:
我想在刀片模板中使用一段简单的代码:
@if($errors->has())
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
@endif
但是为了使用 $errors,我在某处读到需要使用 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
【问题讨论】:
-
你使用的是 laravel 5.2 吗?
-
它是 5.1。我试图遵循链接线程中的一些答案,似乎错误消失了,但是当我尝试访问 $error 时,我现在得到了
exception 'ErrorException' with message 'Undefined variable: errors'视图,就像根本不包含中间件一样。