You can use custom validation rules.
https://laravel.com/docs/5.8/validation#custom-validation-rules
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I will cut it brief, I want to validate the following in a FormRequest:
"dates": ["2019-02-01", ["2019-03-01", "2019-04-01"]]
Basically, allowing single dates and date ranges.
How can I tell the validator I'd like the one or the other, but not both simultaneously?
Currently, I have this for one data type (namely array):
'dates' => 'nullable|array|min:1',
'dates.*' => 'distinct|array|size:2',
'dates.*.0' => 'date_format:Y-m-d',
'dates.*.1' => 'date_format:Y-m-d|after:dates.*.0',
You can use custom validation rules.
https://laravel.com/docs/5.8/validation#custom-validation-rules
Please or to participate in this conversation.