Home >Backend Development >PHP Tutorial >Sometimes $errors does not exist. Why does blade not report an error?

Sometimes $errors does not exist. Why does blade not report an error?

WBOY
WBOYOriginal
2016-08-04 09:20:27946browse

Sometimes $errors does not exist. Why does blade not report an error?

Reply content:

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?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn