My Eloquent model consists of 30 fields.
Validation Rule:
- The first field is required
- Out of the other 29 fields, at least one field is required.
Checking the documentation of Laravel 5.5, I found required_without_all
validation rule quite relatable. One way of writing the above validation rule would be to specify in each of the 29 fields required_without_all:field1,.....,field28
(i.e. the other fields excluding the first and the given field)
But, this requires writing the 28 field names in the validation rule of all the fields excluding the first one. Is there any simpler, non-redundant approach?
$rules[$field].= '|required_without_all:' . implode(',', $fields->whereNotIn(null, [$field])->toArray());
After the change, it is not working any more. My rules for these fields are'sometimes|date_format:Y-m-d'
Is it in relation with thesomething
rule? – Chromatophore