Laravel 5 required_if验证单选按钮

时间:2015-06-02 17:14:41

标签: validation laravel-5

当你有单选按钮时,laravel required_if验证似乎不起作用。

我有以下规则:

'method'  => 'required|in:Email,Url',
'email' => 'required_if:method,Email'|'email',
'url' => 'required_if:method,Url'|'url', 

在我的表格中,我有以下内容:

{!! Form::radio('method', 'Email', true ) !!}
{!! Form::radio('method', 'Url', false ) !!}

{!! Form::text('email', null, ['maxlength' => '255', 'class' => 'form-control']) !!}

{!! Form::text('url', null, ['maxlength' => '1000', 'class' => 'form-control']) !!}

但验证似乎没有解决?

1 个答案:

答案 0 :(得分:1)

我的错误 - 在下面添加了额外的撇号:

'email' => 'required_if:method,Email'|'email',
'url' => 'required_if:method,Url'|'url',

应该是:

'email' => 'required_if:method,Email|email',
'url' => 'required_if:method,Url|url',