$errors 是 laravel 在 response 中自動塞進去的一個屬性,就算你代碼中沒有寫到,他還是會傳一個空的,其類型為
Illuminate\Support\ViewErrorBag
但其實只是用數組乘載 Illuminate\Support\MessageBag
所以當你使用 $errors->first('email') 時,可以根據下面代碼看出來
<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>有值就回傳,沒值就回傳空,所以才不會報錯
因为Laravel 5.2.27开始在每个页面都加上了web中间件,自然不会报错“$errors未定义”。
另外你直接在Views写表单代码?不用点form扩展包吗?
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号