← Back to Course

Using Request Classes for Form Validation

Calling validate() directly inside a controller works well for simple forms, but as validation rules grow more complex, keeping them inline can clutter the controller. Laravel solves this with Form Request classes, which move validation entirely into their own dedicated file.

What Is a Form Request?

A Form Request is a custom class that extends Laravel's base request class, generated through Artisan. Instead of validating manually inside a controller method, the request is simply type-hinted as a parameter, and Laravel runs the validation automatically before the method even executes.

Structuring a Form Request

Each Form Request defines two key pieces: an authorize() method that controls whether the current user is allowed to make this request, and a rules() method that returns the same kind of validation array used with validate().

MethodPurpose
rules()Defines the validation rules for the request
authorize()Determines if the user is permitted to make this request
messages()Optionally overrides default validation error messages
validated()Returns only the fields that passed validation, inside the controller

Why Use Form Requests

Form handling and validation round out the request-side of a Laravel application — but every one of those forms usually ends with data being saved somewhere. That brings us to how Laravel connects to and works with databases, starting with the connection layer itself.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course