2016-08-05 180 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',