When I use $ errors in the view, laravel reports an error, reminding $ errors to be undefined. The server environment is Homestead4.0.0 and Laravel version is 5.2. I have read the instruction in the 5.2 manual that $ errors is available in each view. What is the problem? When I use $ errors in the view, laravel reports an error, reminding $ errors to be undefined. The server environment is Homestead4.0.0 and Laravel version is 5.2.
I have read the instruction in the 5.2 manual that $ errors is available in each view. What is the problem?
Reply content:
When I use $ errors in the view, laravel reports an error, reminding $ errors to be undefined. The server environment is Homestead4.0.0 and Laravel version is 5.2.
I have read the instruction in the 5.2 manual that $ errors is available in each view. What is the problem?
The problem has been solved. Although it is not the question mentioned by @ rainwsy or @ hi, I am very grateful for the answer.
The cause of this problem is the 5.2 source code change, but it is not clearly written in the manual, or I have not read it clearly. Now I will post the solution for a list of friends who have the same requirements:
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.
There are two ways to fix this:
In yourkernel.php
File, you can movemiddleware \Illuminate\View\Middleware\ShareErrorsFromSession::class
Back toprotected $middleware
Property.
You can wrap all your web routes with a route group and applyweb
Middleware to them.
Route::group(['middleware' => 'web'], function() { // Place all your web routes here... });
Original article address: Laravel 5.2 $ errors not appearing in Blade
You must judge whether an error exists before output is displayed.
@if (count($errors) > 0) Whoops! There were some problems with your input.
@foreach ($errors->all() as $error)
- {{ $error }}
@endforeach
@endif
Https://laravel.com/docs/5.2/quickstart-intermediate#validation
The $ errors Variable
Is it necessary to introduce a common file @ include ('common. errors ')
The solution is good. I like it.