Full-Stack Development

Laravel form requests: keeping validation out of controllers

Move input rules and authorization into a dedicated request object.

Anant Dhiman · · 1 min read

Form fields moving from validation errors to successful submission
On this page

Form requests provide a useful boundary between HTTP input and business logic. A controller should orchestrate an operation rather than contain a growing list of validation conditions.

Implementation approach

Define a request class with rules for the actual operation. Use its authorize method for request-level permission checks and pass only validated fields into the service. Never treat validation as a replacement for record-level authorization.

Example

$data = $request->validated();
$service->update($customer, $data);

Validation and edge cases

Test missing fields, invalid types, unauthorized users and attempts to submit fields that are not in the allowlist. In particular, verify that ownership and privileged flags cannot be changed through mass assignment.

Key takeaway

Keep business invariants in the domain or service layer so that background jobs and command-line callers cannot bypass them.

← All insights

Related articles