Skip to content

Mark Ignored Fields as prohibited

Quick Tips•
November 30, 2026

A "change dates" endpoint reads check_in and check_out and nothing else. A client that also sends room_id: 7 passes validation, because room_id has a sometimes rule. The controller ignores it, the reservation keeps its old room, and the response is a 204. The client believes it moved the guest. Nothing in the response says otherwise, and the front desk finds out when the guest arrives.

Don't do this:

PHP
<?php declare(strict_types=1); namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; final class ChangeReservationDatesRequest extends FormRequest { /** * @return array<string, list<string>> */ public function rules(): array { return [ 'room_id' => ['sometimes', 'integer', 'exists:rooms,id'], 'check_in' => ['required', 'date_format:Y-m-d'], 'check_out' => ['required', 'date_format:Y-m-d', 'after:check_in'], ]; } }

Do this instead:

PHP
<?php declare(strict_types=1); namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; final class ChangeReservationDatesRequest extends FormRequest { /** * @return array<string, list<string>> */ public function rules(): array { return [ 'room_id' => ['prohibited'], 'check_in' => ['required', 'date_format:Y-m-d'], 'check_out' => ['required', 'date_format:Y-m-d', 'after:check_in'], ]; } }

With prohibited, a request that sends room_id: 7 gets a 422 with The room id field is prohibited.. The client learns that moving a guest to another room is not what this endpoint does, instead of finding out from the front desk.

The rule passes when the value is absent, null, or an empty string, because validateProhibited is the negation of validateRequired. It stops a client from sending a real value, which is the case that misleads. Add it for every field the endpoint ignores.