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

一世执手 提交于 2019-12-07 08:29:09

问题


When i access my Laravel Project. It Returns Following Errors. How to Solve It.

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)

In my Blade Code :

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

回答1:


Check this line:

@if ($errors->has())

has() is used to filter the selecting model based on a relationship. So it acts very similarly to a normal WHERE condition. If you just use has('relation') that means you only want to get the models that have at least one related model in this relation.

has() must have a string index as its parameter to check whether it exist or not. But in your case it is blank.

Replace the following line:

@if ($errors->has())

with

@if ( count( $errors ) > 0 )

and try again.




回答2:


Instead of

@if ($errors->has())

Use in Laravel 5.3

@if ($errors->count())


来源:https://stackoverflow.com/questions/43445304/missing-argument-1-for-illuminate-support-messagebaghas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!