Saturday, March 19, 2016

Undefined Variable: Errors in Laravel 5.2 Application

Recently in one of my Laravel 5.2 project we were using Laravel model validations on server side, where we faced an issue that on failed validation it goes back to previous view but we did not get any errors as it was giving error undefined variable $errors.

This is a breaking problem with the 5.2 upgrade. What's happening is the middleware which is responsible for making that errors variable available to all your views is not being utilized because it was moved from the global middleware to the web middleware group. So to fix this issue you have to do following.

Wrap all your web routes with a route group and apply the web middleware to them

Route::group(['middleware' => 'web'], function() {
    // all routes.

That's it and now it should work.

No comments:

Post a Comment