最近用laravel5.2的validator时,完全参考手册操作,结果控制器$validator->errors()->all()正常显示错误信息,$validator->fails()也能正常跳转到视图,但在视图中@foreach $errors的结果总是为空,错误信息没办法显示出来。

找了许久,参考:

https://stackoverflow.com/questions/34438463/laravel-5-2-errors-not-appearing-in-blade/36253445#36253445?newreg=d2be163070544c9faa15d63a39c84a21

才发现是我的route.php中为路由组重复使用web中间件所致,在laravel5.2默认是为route.php使用了web中间件的,所以重复加载中间件就可能有这种古怪的问题,如参考文档所述:

Note: If your copy of Laravel has a RouteServiceProvider that already includes the default routes file within the web middleware group, you do not need to manually add the group to your routes.php file.

posted on 2018-05-23 11:14  SHQHDMR  阅读(221)  评论(0编辑  收藏  举报