#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

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