I have a Laravel rule for validation which is like this:-
$ruleCondition = array(
'home_address' => 'required_if:delivery,y',
'office_address' => 'required_if:delivery,y',
'farm_house_address' => 'required_if:delivery,y',
);
If delivery
is y
, then home_address
, office_address
and farm_house_address
are required.
However, I want to modify this a bit. If delivery
is y
, then either one of the home_address
, office_address
or farm_house_address
would be required.
How can I do this?
2
Answers
You can use
sometimes
like thisafter if logic to
$validator->fails()
handle failYou can add additional validators that require each without the otheres:
(note: I’ve not tested this but it should work)
Ref: https://laravel.com/docs/10.x/validation#rule-required-without