1 //import
2 use Illuminate\Support\Facades\Validator;
3
4 // single var check
5 $validator = Validator::make(['data' => $value],
6 ['data' => 'string|min:1|max:10']
7 );
8 if ($validator->fails()) {
9 // your code
10 }
11
12 // array check
13 $validator = Validator::make(['data' => $array],
14 ['email' => 'string|min:1|max:10'],
15 ['username' => 'string|min:1|max:10'],
16 ['password' => 'string|min:1|max:10'],
17 ['...' => '...']
18 );
19
20 if ($validator->fails()) {
21 // your code
22 }
1Accepted
2Active URL
3After (Date)
4After Or Equal (Date)
5Alpha
6Alpha Dash
7Alpha Numeric
8Array
9Bail
10Before (Date)
11Before Or Equal (Date)
12Between
13Boolean
14Confirmed
15Date
16Date Equals
17Date Format
18Different
19Digits
20Digits Between
21Dimensions (Image Files)
22Distinct
23Email
24Ends With
25Exclude If
26Exclude Unless
27Exists (Database)
28File
29Filled
30Greater Than
31Greater Than Or Equal
32Image (File)
33In
34In Array
35Integer
36IP Address
37JSON
38Less Than
39Less Than Or Equal
40Max
41MIME Types
42MIME Type By File Extension
43Min
44Multiple Of
45Not In
46Not Regex
47Nullable
48Numeric
49Password
50Present
51Regular Expression
52Required
53Required If
54Required Unless
55Required With
56Required With All
57Required Without
58Required Without All
59Same
60Size
61Sometimes
62Starts With
63String
64Timezone
65Unique (Database)
66URL
67UUID
1// List of available validation rules:
2Accepted
3Active URL
4After (Date)
5After Or Equal (Date)
6Alpha
7Alpha Dash
8Alpha Numeric
9Array
10Bail
11Before (Date)
12Before Or Equal (Date)
13Between
14Boolean
15Confirmed
16Date
17Date Equals
18Date Format
19Different
20Digits
21Digits Between
22Dimensions (Image Files)
23Distinct
24Email
25Ends With
26Exclude If
27Exclude Unless
28Exists (Database)
29File
30Filled
31Greater Than
32Greater Than Or Equal - gte
33Image (File)
34In
35In Array
36Integer
37IP Address
38JSON
39Less Than
40Less Than Or Equal
41Max
42MIME Types
43MIME Type By File Extension
44Min
45Multiple Of
46Not In
47Not Regex
48Nullable
49Numeric
50Password
51Present
52Regular Expression
53Required
54Required If
55Required Unless
56Required With
57Required With All
58Required Without
59Required Without All
60Same
61Size
62Sometimes
63Starts With
64String
65Timezone
66Unique (Database)
67URL
68UUID
1# <values> = foo,bar,...
2# <field> = array field
3# <characters> = amount of characters
4
5# accepted # active_url
6# after:<tomorrow> # after_or_equal:<tomorrow>
7# alpha # alpha_dash
8# alpha_num # array
9# bail # before:<today>
10# before_or_equal:<today> # between:min,max
11# boolean # confirmed
12# date # date_equals:<today>
13# date_format:<format> # different:<name>
14# digits:<value> # digits_between:min,max
15# dimensions:<min/max_with> # distinct
16# email # ends_with:<values>
17# exclude_if:<field>,<value> # exclude_unless:<field>,<value>
18# exists:<table>,<column> # file
19# filled # gt:<field>
20# gte:<field> # image
21# in:<values> # in_array:<field>
22# integer # ip
23# ipv4 # ipv6
24# json # lt:<field>
25# lte:<field> # max:<value>
26# mimetypes:video/avi,... # mimes:jpeg,bmp,png
27# min:<value> # not_in:<values>
28# not_regex:<pattern> # nullable
29# numeric # password:<auth guard>
30# present # regex:<pattern>
31# required # required_if:<field>,<value>
32# required_unless:<field>,<value> # required_with:<fields>
33# required_with_all:<fields> # required_without:<fields>
34# required_without_all:<fields> # same:<field>
35# size:<characters> # starts_with:<values>
36# string # timezone
37# unique:<table>,<column> # url
38# uuid
1 $messsages = array(
2 'email.required'=>'You cant leave Email field empty',
3 'name.required'=>'You cant leave name field empty',
4 'name.min'=>'The field has to be :min chars long',
5 );
6
7 $rules = array(
8 'email'=>'required|unique:content',
9 'name'=>'required|min:3',
10 );
11
12 $validator = Validator::make(Input::all(), $rules,$messsages);
13