Laravel Validation: Available Validation Rules

  • Active_url.
  • After:date.
  • After_or_equal:date.
  • Alpha.
  • Alpha_dash.
  • Alpha_num.
  • Array.
  • Bail.
  • Before:date.
  • Before_or_equal:date.
  • Between:min,max.
  • Boolean.
  • Confirmed.
  • Date.
  • Date_equals:date.
  • Date_format:format.
  • Different:field.
  • Digits:value.
  • .
  • Digits_between:min,max.
  • Dimensions.
  • Distinct.
  • Email.
  • Exists:table,column.

Basic Usage Of Exists Rule

'state' => 'exists:states'

Specifying A Custom Column Name

'state' => 'exists:states,abbreviation'
'email' => 'exists:connection.staff,email'
Use Illuminate\Validation\Rule;

Validator::make($data, [
    'email' => [
        'required',
        Rule::exists('staff')->where(function ($query) {
            $query->where('account_id', 1);
        }),
    ],
]);
Use Illuminate\Validation\Rule;

Validator::make($data, [
    'zones' => [
        'required',
        Rule::in(['first-zone', 'second-zone']),
    ],
]);
'video' => 'mimetypes:video/avi,video/mpeg,video/quicktime'
  • File.
  • Filled.
  • Gt:field.
  • Gte:field.
  • Image.
  • In:foo,bar,...
  • In_array:anotherfield.*.
  • Integer.
  • Ip.
  • Ipv4.
  • Ipv6.
  • Json.
  • Lt:field.
  • Lte:field.
  • Max:value.
  • Mimetypes:text/plain,...
  • Mimes:foo,bar,...

Basic Usage Of MIME Rule

'photo' => 'mimes:jpeg,bmp,png'
Use Illuminate\Validation\Rule;

Validator::make($data, [
    'toppings' => [
        'required',
        Rule::notIn(['sprinkles', 'cherries']),
    ],
]);
  • Min:value.
  • Not_in:foo,bar,...
  • Not_regex:pattern.
  • Nullable.
  • Numeric.
  • Present.
  • Regex:pattern.
  • Required.
  • Required_if:anotherfield,value,...
  • Required_unless:anotherfield,value,...
  • Required_with:foo,bar,...
  • Required_with_all:foo,bar,...
  • Required_without:foo,bar,...
  • Required_without_all:foo,bar,...
  • Same:field.
  • Size:value.
  • String.
  • Timezone.
  • Unique:table,column,except,idColumn.

Specifying A Custom Column Name:

'email' => 'unique:users,email_address'

Custom Database Connection

'email' => 'unique:connection.users,email_address'

Forcing A Unique Rule To Ignore A Given ID:

Use Illuminate\Validation\Rule;

Validator::make($data, [
    'email' => [
        'required',
        Rule::unique('users')->ignore($user->id),
    ],
]);

Adding Additional Where Clauses:

'email' => Rule::unique('users')->where(function ($query) {
    return $query->where('account_id', 1);
})
  • Url.

Laravel Validation: Available Validation Rules — Structure map

Clickable & Draggable!

Laravel Validation: Available Validation Rules — Related pages: