Laravel required_without
is not working when I'm passing multiple fields.
This is my rules:
$rules = [
'startDate' => 'date|date_format:m/d/Y|required_without:customerId,purchaseId,orderId',
'endDate' => 'date|date_format:m/d/Y|required_without:customerId,purchaseId,orderId',
];
What I want, when I pass customerId
or purchaseId
or orderId
(but not all) then I shouldn't be getting any error. But it is giving me any error that startDate
is required.
Any assistance will be highly appreciated.
I believe, the rule you are looking for is required_without_all IE. the startDate field must be present when all of the other specified fields (customerId,purchaseId,orderId) are not present.
As per https://laravel.com/docs/5.6/validation
required_without_all:foo,bar,... The field under validation must be present and not empty only when all of the other specified fields are not present.
In contrast to
required_with:foo,bar,... The field under validation must be present and not empty only if any of the other specified fields are present.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With