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

Advanced email validation

The email rule accepts parameters that let you choose how the address is validated:
The rfc validator checks the address against supported RFCs, while dns ensures that the address’s domain has a valid MX record. The dns validator performs a real DNS lookup, but does not determine whether an individual mailbox exists. You can also use the fluent rule builder:
To keep tests from relying on live DNS lookups, use Validator::fakeDnsLookups. This fakes the dns lookup while other requested validations, such as rfc, continue to run:
The dns and spoof validators require the PHP intl extension.

Validating array keys

The array_keys rule validates that the value under validation is a PHP array whose keys are all included in the given list. At least one key must be provided:
For a fluent rule object, use the Rule::arrayKeys method:
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.

Specify password complexity and length

The Password rule object lets you define password complexity and minimum and maximum lengths together.
min() sets the minimum length, while max() sets the maximum length. Use max() to make the accepted upper bound explicit when integrating with storage or external services.

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 August 21, 2026