I need an error message that essentially says "You need to have checked at least one box in at least one multi-dropdown"
My five multi-dropdown names are; Country, County, Gor, Locauth, Parlc.
My controller so far is;
$rules = Array
(
[country] => required_without_all:county,gor,locauth,parlc
[county] => required_without_all:country,gor,locauth,parlc
[gor] => required_without_all:country,county,locauth,parlc
[locauth] => required_without_all:country,county,gor,parlc
[parlc] => required_without_all:country,county,gor,locauth
)
$validator = \Validator::make($input, $rules);
My problem is that I cannot see a way of returning just the one rule. It returns 5 very similar worded rules;
The country field is required when none of county / gor / locauth / parlc are present.
The county field is required when none of country / gor / locauth / parlc are present.
The gor field is required when none of country / county / locauth / parlc are present.
The locauth field is required when none of country / county / gor / parlc are present.
The parlc field is required when none of country / county / gor / locauth are present.
Not brilliant! Is there a way to return just one custom message?
--- EDIT ---
I should add... The Array() code above is not the actual code, that was a print_r result of the actual code which creates those rules. I just thought it would make it easier to read and understand my problem. The actual code, if you're interested is this;
$fields = ['country','county','gor','locauth','parlc'];
$rules = [];
foreach ($fields as $i => $field) {
$rules[$field] = 'required_without_all:' . implode(',', array_except($fields, $i));
}
--- ANOTHER EDIT ---
I already know about custom error messages like;
$messages = [
'required' => 'The :attribute field is required.',
];
$validator = Validator::make($input, $rules, $messages);
But this will just give me five error messages instead of only one.
foreach? Its better you post the whole coderequired_without_all. You cannot do that in just one rule - can you? You have to do that 5 times.