Laravel's question about $ errors Variables

Source: Internet
Author: User
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:

  1. In yourkernel.phpFile, you can movemiddleware \Illuminate\View\Middleware\ShareErrorsFromSession::classBack toprotected $middlewareProperty.

  2. You can wrap all your web routes with a route group and applywebMiddleware 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.