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

eyantra's avatar

Validate text field with required_if for date value

How i can validate the text field with required_if for date value is after_or_equal ??

backups.*.backupName' => 'nullable|required_if:date_from,after_or_equal:today|

I tried above, but not working.

0 likes
3 replies
Nakov's avatar

You can apply the dates on the date itself, and not on the backupName as I guess the date for the backup cannot be an old value neither, right?

So just:

'date_from' => 'nullable|date|after_or_equal:today'
'backups.*.backupName' => 'nullable|required_with:date_from|
eyantra's avatar

No. date_from can be old date, but i want backupName is required only if date_from is today or greater.

eyantra's avatar

I think i need to wite a custom validation.

For now i have put the valodation with condition as:

if($date_from > new DateTime()){ do validation }

Please or to participate in this conversation.