Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mabdullahsari's avatar

Allow multiple validation types in form requests

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',
0 likes
5 replies
mabdullahsari's avatar

Should have mentioned whether this is possible with a combination of the built-in validators. Thanks for the suggestion.

Tray2's avatar

You can do some pretty advanced stuff with the built in ones but this is something I don't think is supported out of the box.

mabdullahsari's avatar

Alright, just wanted to make sure before going down that route. Thanks for the quick replies!

Please or to participate in this conversation.