问题
I have two field billable_option
and billable_option_yes
. I want to validate at least one field is mandatory. I have tried:
$this->validate($request,[
'billable_option'=>'required'|'billable_option_yes'=>'required',
]);
I want to check at least one field is required in Laravel-5.3
.
回答1:
you can try with the required_without.
$rules = array(
'billable_option' => 'required_without:billable_option_yes',
'billable_option_yes' => 'required_without:billable_option'
);
回答2:
Try checking out required_without_all:foo,bar,..., it looks like that should do it for you. To quote their documentation:
The field under validation must be present only when the all of the other specified fields are not present.
Example:
$rules = array(
'billable_option' => 'required_without_all:billable_option_yes',
'billable_option_yes' => 'required_without_all:billable_option'
);
$validator = Validator::make(Input::all(), $rules);
Hope this helps you!
来源:https://stackoverflow.com/questions/46909982/laravel-at-least-one-field-is-required