您好,欢迎访问一九零五行业门户网

这个$errors有时候不存在,为什么blade不报错呢?

回复内容:
$errors 是 laravel 在 response 中自動塞進去的一個屬性,就算你代碼中沒有寫到,他還是會傳一個空的,其類型為
illuminate\support\viewerrorbag
但其實只是用數組乘載 illuminate\support\messagebag
所以當你使用 $errors->first('email') 時,可以根據下面代碼看出來
/** * 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] : '';}
有值就回傳,沒值就回傳空,所以才不會報錯
因为laravel 5.2.27开始在每个页面都加上了web中间件,自然不会报错“$errors未定义”。
另外你直接在views写表单代码?不用点form扩展包吗?
其它类似信息

推荐信息