Update from Laravel 5.2.27
Laravel now supports network middleware by default, as you can here: source
In other words, you no longer need to wrap routes around the middleware group because it does this for you in the RouteServiceProvider file. However, if you are using the Laravel version between 5.2.0 and 5.2.26, refer to the following method:
The following applies only to Laravel 5.2.0 to 5.2.26
Without seeing your routes.php or Kernel.php , I suspect this is happening.
The mode of operation of middlewares has changed from 5.2 and 5.1. In 5.1, you will see this in your app/Http/Kernel.php :
protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \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, ];
This array is your global HTTP middleware stack. In other words, they run in every request. Pay attention to this middleware: Illuminate\View\Middleware\ShareErrorsFromSession . This is what adds the $errors variable for each request.
However, in 5.2, everything changed to use both the web interface and the API in one application. Now you will see this in the same file:
protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::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', ], ];
The global middleware stack now only checks for service. You now have an intermediate group called "web" that includes most of the previous global middleware. Remember that this is the way to enable both the web interface and the API in one application.
So how can we return this $errors variable?
In your routes file, you need to add your routes to the middleware group to access this $errors variable for each request. Like this:
Route::group(['middleware' => ['web']], function () {
If you are not going to create an API, another option is to move the web intermediaries to the global middleware stack, as in 5.1.