ErrorBag is always empty in Laravel 5.2

元气小坏坏 提交于 2019-11-26 11:40:02

问题


I was creating a new Laravel project and when debugging the errors of a form request, I noticed that my ErrorBag was always empty. Even when in the controller $validator->fails() returned true. I tried every solution I found on the internet but nothing worked.

Even when creating a fresh project with composer (as described here) my out of the box auth system has an empty error bag when leaving all the field empty.

And yes, all the routes are using the middleware group web.

Any ideas what is causing this problem? (Session::put() and Session::get() are working)


回答1:


As of v5.2.27, released on 2015-03-25, all routes in app\Http\routes.php are now in the web middleware group by default. If you have explicitly specified this middleware group inside your app\Http\routes.php file, you should remove it and that should resolve your issue.




回答2:


In my case, I moved \Illuminate\Session\Middleware\StartSession::class from my web group to the $middleware array.




回答3:


Are you triggering any form validation errors? If you are then try this -

$messages = $validator->errors();

The messages variable should now have your errors

If you error bag is still empty

  • Check if your post data are being posted to the proper route/controller


来源:https://stackoverflow.com/questions/36377420/errorbag-is-always-empty-in-laravel-5-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!