Free tool · runs in your browser
✅ Laravel Validation Rule Builder
Describe your form fields and get Laravel validation rules as a FormRequest class, a rules array, pipe strings or an inline $request->validate() call. Output checked against Laravel’s own validator.
Start from an example
Runs in your browser: what you enter is never sent anywhere. We only count anonymous usage, such as which buttons are used, to improve the tools.
How Laravel validation rules fit together
Each field gets a list of rules that run in order. Start with presence (required, nullable or sometimes), then the type (string, integer, array, image…), then limits like min, max and unique. The type matters: max:10 means 10 characters for a string, the value 10 for an integer, 10 items for an array and 10 KB for a file.
Use name.* keys to validate every item in a list, and dot notation such as address.city for nested input.
Using the generated FormRequest
- Create it with
php artisan make:request StorePostRequestand paste the code, or save the file toapp/Http/Requests. - Type-hint it in the controller:
public function store(StorePostRequest $request). Laravel validates before your method runs. - Read only the checked input with
$request->validated(), never$request->all(), so unexpected fields can’t reach your models. - Replace
return trueinauthorize()with a real check, such as$this->user()->can('create', Post::class).
Frequently asked questions
Should I use pipe strings or arrays for Laravel validation rules?
Arrays. They let you mix in rule objects such as Rule::unique() or Password::min(8), and they are required when a regex contains a "|". Pipe strings like "required|string|max:255" are shorter and work the same for simple rules.
What is the difference between nullable and sometimes in Laravel?
"nullable" lets the field be empty or null while still validating any value that is sent. "sometimes" only validates the field when it is present in the request, which suits PATCH updates; combine it with "required" so a present field cannot be empty.
How do I ignore the current record in a unique rule when updating?
Use the rule object: Rule::unique('users', 'email')->ignore($this->user()->id). In a FormRequest you can read the route model with $this->route('user').
Why use a FormRequest instead of $request->validate()?
A FormRequest keeps validation and authorization out of the controller, can be reused by several actions, and lets you add messages(), attributes() and prepareForValidation(). Inline $request->validate() is fine for small, one-off actions.
What unit does max use for file uploads?
Kilobytes. max:2048 allows files up to 2 MB. For strings max counts characters, for numbers it is the value (when the field also has numeric or integer), and for arrays it is the number of items.