laravel框架表单验证出错Undefined variable: errors

在使用laravel混合开发的时候

就是不是前后端分离,将模板文件写在resource中

在表单验证的时候出现以下问题

`Undefined variable: errors (View: C:\wamp\www\StuLaravel5\resources\views\login.blade.php)`

解决办法:

```

在使用$error时需要用到中间件:

\Illuminate\Session\Middleware\StartSession::class,

\Illuminate\View\Middleware\ShareErrorsFromSession::class,
```

以下为中间件

```
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
];
```

    A+
发布日期:2022年09月06日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: