The Validator class helps to validate input fields in Laravel. There are various validation rules available to validate fields. The required_without
validation rule is used to check whether one of the other fields must be present and not empty.
Use the required_without rule in Laravel Validation, to validate one of two fields must be filled.
$validator = Validator::make(
$this->request->all(),
[
'email' => 'required_without:business_email',
'business_email' => 'required_without:email'
],
[
'email.required_without' => 'Please provide your personal email or business email.',
'business_email.required_without' => 'Please provide your business email or personal email.',
]
);
If one field is required more than two fields, use required_without_all:foo,bar,…