Welcome Guest, Not a member yet? Register   Sign In
Validation for Multiple Input Requirements?

Do you know if there exists a validation rule that can be employed in situations where a controller can accept multiple inputs, each accompanied by the permit_empty modifier, yet necessitating at least one input to possess a value for functional utility? To elaborate, consider a 'cars' controller endowed with search fields like 'color,' 'style,' and 'engine type' - is there a validation rule that can ascertain the presence of a value in at least one of these fields, regardless of which one? Presently, my approach involves scrutinizing if all fields are void of content and subsequently triggering an exception. However, it would be notably more elegant if the validator could oversee this task. Your insights would be greatly appreciated. Thank you!

(This post was last modified: 08-07-2023, 01:25 AM by sammyskills.)

The required_without rule should come in handy for this. From the docs

Quote:The field is required when any of the other fields is empty() in the data.

So, in your case, you can do something like so:

PHP Code:
$rules = [
    'color' => "required_without[style,engine_type]",
    'style' => "required_without[color,engine_type]",
    'engine_type' => "required_without[color,style]",

I hope that helps.

Theme © iAndrew 2016 - Forum software by © MyBB