我有一段简单的代码,我想在刀片模板中使用:
@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);
到应用程序.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
解决方案是将其添加到 app.php:
$app->middleware([
Illuminate'Session'Middleware'StartSession::class,
Illuminate'View'Middleware'ShareErrorsFromSession::class
]);