不可修复的未定义的变量错误laravel 5.2

问题描述:

I keep having this error every time I try to validate a form:

Undefined variable: errors (View: /home/vagrant/Code/talents/resources/views/welcome.blade.php)

I tried modifying the kernel.php file, and also adding the route into the 'middleware' => 'web' in the routes file, but none of those seem to fix the problem.

Undefined variable: errors in Laravel

If you need access to session errors you need sessions. You should move your '/' route to the 'web' middleware group.

Route::group(['middleware' => ['web']], function () {
    Route::get('/', function () {
        return view('welcome');
    });        
});

The 'web' middleware group gives you sessions and the session errors.

If you have this setup at the moment and are still having that issue, you may want to change any adjustments you made to Kernel.php and use the default one. If you change the middleware applied to the 'web' group, you could cause an issue where things dont get applied correctly.

In regard to the session errors, those are being shared with views in \Illuminate\View\Middleware\ShareErrorsFromSession, which the 'web' middleware group has applied.

Solved

You may change any one of the following:

1. put your working route (app/http/routes.php) on

Route::group(['middleware' => ['web']], function () { // Here like Route::get('/', 'TodoController@index'); Route::post('/', 'TodoController@store'); });

See the image here

2. Move your protected $middlewareGroups web (app/Http/Kernel.php) on protected $middleware = []

See the image here