Skip to content

Don't Spread validated() Into create()

Quick Tips•
October 22, 2026

validated() returns every key that has a rule and passed, including rules that exist for a different endpoint. ReservationRequest is shared with the PATCH endpoint that cancels and checks in, so it has a status rule. The store endpoint never reads status, but the spread hands it to create() anyway. The spread comes last, so it overrides the controller's own 'status' => ReservationStatus::CONFIRMED, and a client that POSTs "status": "checked_in" gets a reservation that is already checked in.

Don't do this:

PHP
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Http\Requests\ReservationRequest; use App\Models\Reservation; use App\Models\ReservationStatus; use Illuminate\Http\JsonResponse; use Illuminate\Support\Str; final readonly class StoreReservationController { public function __invoke(ReservationRequest $request): JsonResponse { $reservation = Reservation::query()->create([ 'guest_id' => $request->user()->guest_id, 'status' => ReservationStatus::CONFIRMED, 'confirmation_code' => Str::upper(Str::random(8)), ...$request->validated(), ]); return new JsonResponse($reservation, 201); } }

Do this instead:

PHP
<?php declare(strict_types=1); namespace App\Http\Controllers; use App\Http\Requests\ReservationRequest; use App\Models\Reservation; use App\Models\ReservationStatus; use Illuminate\Http\JsonResponse; use Illuminate\Support\Str; final readonly class StoreReservationController { public function __invoke(ReservationRequest $request): JsonResponse { $reservation = Reservation::query()->create([ 'guest_id' => $request->user()->guest_id, 'status' => ReservationStatus::CONFIRMED, 'confirmation_code' => Str::upper(Str::random(8)), 'room_id' => $request->validated('room_id'), 'check_in' => $request->validated('check_in'), 'check_out' => $request->validated('check_out'), 'adults' => $request->validated('adults'), ]); return new JsonResponse($reservation, 201); } }

Now the controller lists every column it writes. A new rule on the shared request cannot change what this endpoint stores, and a new column is a line you see in review.

$fillable does not close the gap. status is a column staff legitimately set, so it is in the list. $fillable says what the model can ever accept, not what this endpoint should accept. In PHP 8.1 and later, spreading an array with string keys lets the later key win, which is why the order of the spread decides the outcome.