2017-10-05 96 views
-1

我正在驗證Laravel中的表單,但我沒有收到空錯誤消息。Laravel驗證器返回空錯誤消息

$validator = Validator::make($all, [ 
        'email' => 'required|email', 
        'email_confirmation' => 'required', 
        'first_name' => 'required', 
        'last_name' => 'required', 
        'gender' => 'required', 
        'year' => 'required', 
        'month' => 'required', 
        'day' => 'required', 
        'birth_country' => 'required', 
        'birth_city' => 'required', 
        'native_country' => 'required', 
        'password' => 'required', 
        'password_confirmation' => 'required', 
        'address' => 'required', 
        'country' => 'required', 
        'region' => 'required', 
        'city' => 'required', 
        'tel_area_code' => 'required', 
        'tel_number' => 'required', 
        'postal_code' => 'required', 
        'mobile_area_code' => 'required', 
        'mobile_number' => 'required', 
        'terms_cond_check' => 'required', 
       ],[ 
        'terms_cond_check.required' => 'You must agree to our Terms and Conditions', 
       ]); 

的響應是

MessageBag {#568 ▼ 
    #messages: array:10 [▼ 
    "password" => array:1 [▼ 
     0 => "" 
    ] 
    "password_confirmation" => array:1 [▼ 
     0 => "" 
    ] 
    "address" => array:1 [▼ 
     0 => "" 
    ] 
    "region" => array:1 [▼ 
     0 => "" 
    ] 
    "city" => array:1 [▼ 
     0 => "" 
    ] 
    "tel_area_code" => array:1 [▼ 
     0 => "" 
    ] 
    "tel_number" => array:1 [▼ 
     0 => "" 
    ] 
    "postal_code" => array:1 [▼ 
     0 => "" 
    ] 
    "mobile_area_code" => array:1 [▼ 
     0 => "" 
    ] 
    "mobile_number" => array:1 [▼ 
     0 => "" 
    ] 
    ] 
    #format: ":message" 
} 
+0

你能告訴你的形式? –

回答

1

首先你需要在表格視圖重定向的。我的意思是你的驗證

if ($validator->fails()) { 
     return redirect(route('tape here your form route (you can find that in route/web.php)')) 
      ->withErrors($validator) 
      ->withInput(); 
    } 

之後,你需要顯示錶單視圖所有錯誤消息後添加此 。

只需添加這對您的表單視圖頁面的頂部顯示所有的錯誤信息:

<div class="alert alert-danger"> 
    <ul> 
     @foreach ($errors->all() as $error) 
      <li>{{ $error }}</li> 
      @endforeach 
    </ul> 
</div> 
+0

錯誤消息包爲空 – baig772

+0

您需要用$ request-> all()替換$ all。在你的驗證器:: make方法 –