Skip to content

Instantly share code, notes, and snippets.

View judgej's full-sized avatar

Jason Judge judgej

View GitHub Profile
@judgej
judgej / open-ended-date-range.md
Last active January 29, 2024 17:55
Open-ended Date Range Validation

The Problem

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.