Skip to content

The date Rule Accepts Dates Your Query Doesn't

Quick Tips•
November 19, 2026

The date rule accepts anything PHP's date parser reads. validateDate calls strtotime() and date_parse() on the string, and 10/01/2026 passes both, read as 1 October (month first). A client in Europe means 10 January. The controller then passes the raw string to where('check_in', '>=', ...), and the database receives a literal that the rule never pinned to one format. The rule and the query disagree about what a date looks like.

Don't do this:

PHP
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Models\Reservation; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; final readonly class ListReservationsController { public function __invoke(Request $request): JsonResponse { $request->validate([ 'check_in_from' => ['sometimes', 'date'], ]); $reservations = Reservation::query() ->when( $request->filled('check_in_from'), fn (Builder $query) => $query->where('check_in', '>=', $request->input('check_in_from')), ) ->paginate(25); return new JsonResponse($reservations); } }

Do this instead:

PHP
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Models\Reservation; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; final readonly class ListReservationsController { public function __invoke(Request $request): JsonResponse { $request->validate([ 'check_in_from' => ['sometimes', 'date_format:Y-m-d'], ]); $checkInFrom = $request->date('check_in_from', 'Y-m-d'); $reservations = Reservation::query() ->when( $checkInFrom !== null, fn (Builder $query) => $query->where('check_in', '>=', $checkInFrom->format('Y-m-d')), ) ->paginate(25); return new JsonResponse($reservations); } }

date_format:Y-m-d accepts one shape, so 10/01/2026 now fails with a 422 that says the field must match the format. $request->date('check_in_from', 'Y-m-d') returns null when the field is absent and otherwise builds a Carbon date with createFromFormat. The query receives a string you formatted yourself, not one the client chose.