Backend Development 2 min read

Laravel Validation Cheat Sheet

This article provides a concise Laravel validation cheat sheet that explains the purpose of the Validation helper, shows common code examples for creating and extending validators, and lists the most frequently used validation rules with their syntax for quick reference.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Laravel Validation Cheat Sheet

Validation Cheat Sheet

Validation is the validator helper in Laravel and is crucial for data validation.

Code Examples

Validator::make(
    array('key' => 'Foo'),
    array('key' => 'required|in:Foo')
);

Validator::extend('foo', function($attribute, $value, $params) {
    // custom rule logic
});

Validator::extend('foo', 'FooValidator@validate');

Validator::resolver(function($translator, $data, $rules, $msgs) {
    return new FooValidator($translator, $data, $rules, $msgs);
});

Common Validation Rules

accepted
active_url
after:YYYY-MM-DD
before:YYYY-MM-DD
alpha
alpha_dash
alpha_num
array
between:1,10
confirmed
date
date_format:YYYY-MM-DD
different:fieldname
digits:value
digits_between:min,max
boolean
email
exists:table,column
image
in:foo,bar,...
not_in:foo,bar,...
integer
numeric
ip
max:value
min:value
mimes:jpeg,png
regex:[0-9]
required
required_if:field,value
required_with:foo,bar,...
required_with_all:foo,bar,...
required_without:foo,bar,...
required_without_all:foo,bar,...
same:field
size:value
timezone
unique:table,column,except,idColumn
url

Motivational Note

Helping others helps yourself; technology shapes life, and knowledge changes destiny!

backendValidationPHPLaravelrulesCheat Sheet
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.