Laravel 9, PHP 8.1. I had a form with two fields, start_date
and end_date
.
These fields were nullable, so either could be left blank to set an pen-ended start or end of the date range.
The dates needed to be validated to ensure the end date was after the start date,
and the start date was before the end date. But only when both are set.
The problem with applying the before
and after
validation rules is that if the field being compared
against is empty, then the validation rule always failed.