2017-04-17 57 views
2

缺少參數1當我訪問我的Laravel項目時。它返回以下錯誤。如何解決它。Illuminate Support MessageBag :: has()

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) 

在我的刀片代碼:

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

回答

6

檢查這一行:

@if ($errors->has()) 

has()用於過濾基於關係的選擇模型。所以它的行爲非常類似於正常的WHERE條件。如果你只是使用has('relation')這意味着你只想得到這個關係中至少有一個相關模型的模型。

has()必須有一個字符串索引作爲它的參數來檢查它是否存在。但在你的情況下,它是空白的。

替換以下行:

@if ($errors->has()) 

@if (count($errors) > 0) 

,然後再試一次。

+0

謝謝@MayankPandeyz – Karthikvijayaveni

+0

聽起來不錯!繼續問好問題:) –

相關問題