Home >Backend Development >PHP Tutorial >Sometimes $errors does not exist. Why does blade not report an error?
$errors
is an attribute automatically inserted by laravel
in response
. Even if it is not written in your code, it will still pass an empty value whose type is
IlluminateSupportViewErrorBag
But it’s actually just multiplied by an array IlluminateSupportMessageBag
So when you use $errors->first('email')
, you can see it from the following code
<code class="php">/** * Get the first message from the bag for a given key. * * @param string $key * @param string $format * @return string */ public function first($key = null, $format = null) { $messages = is_null($key) ? $this->all($format) : $this->get($key, $format); return count($messages) > 0 ? $messages[0] : ''; }</code>
If there is a value, it will be returned. If there is no value, it will be returned empty, so no error will be reported
Because Laravel 5.2.27 has added web middleware to every page, naturally the error "$errors is not defined" will not be reported.
Also, do you write the form code directly in Views? Don’t you need to click on the form extension package?