2016-08-05 185 views
1

這裏`required_without_all`驗證異常都是事實:自定義錯誤消息和Laravel 5.1

  • 我有許多領域
  • 三年領域的一種形式,我只需要其中的一個需要填補
  • 我在自定義表單要求設定爲required_without_all:這三個領域
  • 我在validation.php修改:attribute爲我所需的字段
  • 有問題的表單字段我的應用程序中是唯一的

這裏有問題:

  • 當我輸入的emerg_contact_home_phone領域的一個電話號碼,其他兩個不顯示錯誤,這是正確的。
  • 當我在emerg_contact_work_phone字段中輸入電話號碼時,emerg_contact_mobile_phone顯示錯誤。
  • 當我在emerg_contact_mobile_phone字段中輸入電話號碼時,emerg_contact_home_phoneemerg_contact_work_phone都顯示錯誤。
  • 顯示錯誤消息時,emerg_contact_mobile_phone未顯示修改後的屬性「移動電話」,而是顯示「emerg_contact_mobile_phone」。

這裏是我試過:

  • 我有三重檢查格式的名稱的拼寫中的所有位置。
  • 我堅定地認爲問題已經與emerg_contact_mobile_phone領域做的,所以我試圖改變名稱,以不同的東西(即:「MOBILE_PHONE」)

這裏是我的代碼:

形式.blade.php:

 <tr> 
      <td class="col-md-4"> 
       {!! Form::label('emerg_contact_work_phone', '* Work Phone:', array('class' => 'control-label')) !!} 
      </td> 
      <td class="{{ $errors->has('emerg_contact_work_phone') ? 'has-error' : ''}}"> 
       {!! Form::text('emerg_contact_work_phone', null, array('class' => 'form-control')) !!} 
       {!! $errors->first('emerg_contact_work_phone', '<span class="help-block">:message</span>') !!} 
      </td> 
     </tr> 
     <tr> 
      <td class="col-md-4"> 
       {!! Form::label('emerg_contact_home_phone', '* Home Phone:', array('class' => 'control-label')) !!} 
      </td> 
      <td class="{{ $errors->has('emerg_contact_home_phone') ? 'has-error' : ''}}"> 
       {!! Form::text('emerg_contact_home_phone', null, array('class' => 'form-control')) !!} 
       {!! $errors->first('emerg_contact_home_phone', '<span class="help-block">:message</span>') !!} 
      </td> 
     </tr> 
     <tr> 
      <td class="col-md-4"> 
       {!! Form::label('emerg_contact_mobile_phone', '* Mobile Phone:', array('class' => 'control-label')) !!} 
      </td> 
      <td class="{{ $errors->has('emerg_contact_mobile_phone') ? 'has-error' : ''}}"> 
       {!! Form::text('emerg_contact_mobile_phone', null, array('class' => 'form-control')) !!} 
       {!! $errors->first('emerg_contact_mobile_phone', '<span class="help-block">:message</span>') !!} 
      </td> 
     </tr> 

validation.php:

'attributes' => [ 
    'givenname' => 'First Name', 
    'surname' => 'Last Name', 
    'email' => 'Email', 
    'emerg_contact_relationship' => 'Relationship', 
    'emerg_contact_givenname' => 'First Name', 
    'emerg_contact_surname' => 'Last Name', 
    'emerg_contact_work_phone' => 'Work Phone', 
    'emerg_contact_home_phone' => 'Home Phone', 
    'emerg_contact_mobile_phone' => 'Mobile Phone', 
], 

CustomFormRequest.php:

public function rules() 
{ 
    return [ 
     'givenname' => 'required', 
     'surname' => 'required', 
     'email' => 'required|email|unique:employees,email,' . $this->get('id'), 
     'password' => 'required_with:is_user|min:6', 
     'password_confirmation' => 'required_with:is_user|min:6|same:password', 
     'aca_number' => 'unique:employees,aca_number,' . $this->get('id'), 
     'license_number' => 'unique:employees,license_number,' . $this->get('id'), 
     'base_location' => 'required', 
     'emerg_contact_relationship' => 'required', 
     'emerg_contact_givenname' => 'required', 
     'emerg_contact_surname' => 'required', 
     'emerg_contact_home_phone' => 'required_without_all:emerg_contact_work_phone, emerg_contact_mobile_phone', 
     'emerg_contact_work_phone' => 'required_without_all:emerg_contact_home_phone, emerg_contact_mobile_phone', 
     'emerg_contact_mobile_phone' => 'required_without_all:emerg_contact_home_phone, emerg_contact_work_phone', 
    ]; 
} 
+1

只是爲了嘗試,採取了逗號和下一列之間的空間。 'emerg_contact_work_phone,emerg_contact_mobile_phone' – aynber

+0

神聖的母親......趕上!最好提交,作爲回答:) –

+0

哈!我實際上並不確定是否是這種情況,但所有示例都不使用空格。 – aynber

回答

2

列應該是逗號沒有空格分隔:

'emerg_contact_home_phone' => 'required_without_all:emerg_contact_work_phone,emerg_contact_mobile_phone',