laravel-validation

Installation
SKILL.md

Laravel Validation

Every input an endpoint accepts is validated by a Form Request, and the Form Request does nothing else. It doesn't authorize: the route does. It doesn't map: the code that builds the DTO reads the validated request. Each Form Request is pinned by a dataset-driven test that sends a broken request to the real endpoint, one rule per case, and asserts the exact message.

Rules

  • A Form Request validates every input. Never $request->validate() or Validator::make() in a controller. laravel-data's validation is switched off, so the Form Request is the only validation that runs (see laravel-dtos).
  • One request per surface and operation. App\Http\{Surface}\Requests\{Verb}{Entity}Request, for example App\Http\Api\V1\Requests\CreateOrderRequest. When two surfaces take the same input, each gets its own request, so one surface's contract can change without touching the other's.
  • A request only validates. No authorize(): authorization is ->can() on the route (see laravel-routing). No toDto(), prepareForValidation() or passedValidation(): mapping and casting happen where the DTO is built, through typed request helpers.
  • Array rules, one per line. Never a pipe string. Each rule gets its own line, so a diff shows exactly which rule changed and a rule object sits alongside the strings.
  • Order: presence, type, bounds, then the expensive checks. required or nullable first, then the type (string, integer, array), then size and format, then database lookups and rule objects.
  • bail sits just before the rule it protects. It applies to the whole attribute wherever it appears; Laravel treats it as a flag, not a position. Placing it before the lookup or rule object tells the reader what the type checks guard, and that check never runs on input that already failed.
  • Enums use new Enum(OrderPriority::class), after 'string' and 'bail'. Never an in: list of case values: the list goes stale when a case is added.
  • Name fields in attributes(), not messages(). Laravel builds every message from the attribute's name, so mapping items.*.product_ulid to product fixes all of that field's messages at once. Use messages() only for wording the attribute name can't produce. A rule object writes its own message.

Example

<?php
Installs
56
GitHub Stars
15
First Seen
Mar 27, 2026