Skip to main content

What is validation?

Validation is the process of verifying that data submitted by the user meets the format and rules your application expects. Laravel provides a simple, expressive validation system built into the request object, with no third-party packages required.

Validating in a controller

Using $request->validate()

The most straightforward way to validate incoming data is to call $request->validate() inside a controller method. If validation fails, Laravel automatically redirects the user back to the previous page and stores the error messages in the session. First, define your routes:
Then write the controller:
Pass an array to validate where each key is a field name and each value is the validation rules for that field. You can express rules either as a pipe-delimited string or as an array:

Common validation rules

For the full list of available validation rules, see the official documentation.

Using validated data

The validate method returns only the data that passed validation. Use this array directly — it contains nothing more than what you explicitly declared:

Displaying errors in Blade

When validation fails, Laravel makes an $errors variable available in every view. The ShareErrorsFromSession middleware in the web middleware group handles this automatically.

Display all errors

Display errors per field

Use the @error directive to show an inline error message for a specific field:
Use old('field') to repopulate form fields with the user’s previous input after a validation failure.

Form request classes

When to use them

When validation logic becomes complex, extract it into a dedicated “form request” class. A form request encapsulates both the validation rules and the authorization check for a request.

Creating a form request

Use the make:request Artisan command:
This creates app/Http/Requests/StorePostRequest.php:

The rules() method

Return your validation rules as an array, using the same format as $request->validate().

The authorize() method

Return true to allow the request, or false to automatically return a 403 response. You can check the authenticated user here. For tutorials, returning true is fine.
If authorize returns false, Laravel returns a 403 Forbidden response and the controller method is never called.

Using the form request in a controller

Type-hint the form request class on your controller method. Laravel validates and authorizes the request before your method is called, so you can skip writing any validation code inside the method:
Call $request->validated() to retrieve only the data that passed validation.

Practical example: a post creation form

Here is the full flow — from displaying a form to validating and saving the data.
1

Define routes

2

Create a form request

3

Implement the controller

4

Create the Blade template

Always include the @csrf directive in your Blade forms. Without it, Laravel returns a 419 error.

Next steps

Controllers

Review how to organize request handling logic in controller classes.
Last modified on April 7, 2026