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
1$input = $request->only('account'); // dont use all(), ever
2
3$rules = [
4 'account' => 'required'
5];
6
7if (filter_var($input['account'], FILTER_VALIDATE_EMAIL)) {
8
9 $rules['account'] .= '|exists:users,email';
10
11} else {
12
13 $rules['account'] .= '|exists:users,username';
14
15}
16
17$messages = [
18 'account.required' => 'Enter username or email to login.',
19];
20
21$validator = Validator::make($input, $rules, $messages);
1 $validator = Validator::make($request->all(), []);
2
3 $validator->sometimes('email', 'unique:users,email', function ($input) {
4 return $input->email !== Auth::user()->email;
5 });
6//@sujay