Illuminate\Support\MessageBag::has() 缺少参数 1

Missing argument 1 for Illuminate\Support\MessageBag::has()

当我访问我的 Laravel 项目时。它 Returns 以下错误。如何解决。

Missing argument 1 for Illuminate\Support\MessageBag::has(), called in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Support/ViewErrorBag.php on line 92 and defined (View: /var/www/laravel/resources/views/welcome.blade.php)

在我的 Blade 代码中:

  @if ($errors->has())
  <div class="alert alert-danger">
  @foreach ($errors->all() as $error)
    {{ $error }}<br>
  @endforeach
  </div>
  @endif

检查这一行:

@if ($errors->has())

has()用于根据关系筛选选择模型。所以它的行为与正常的 WHERE 条件非常相似。如果你只使用 has('relation') 那意味着你只想得到至少有一个相关模型在这个关系中的模型。

has()必须有一个字符串索引作为它的参数来检查它是否存在。但在你的情况下它是空白的。

替换以下行:

@if ($errors->has())

@if ($errors->count())

然后重试。

而不是

@if ($errors->has())

在Laravel 5.3

中使用
@if ($errors->count())