1/**
2 * Store a new blog post.
3 *
4 * @param Request $request
5 * @return Response
6 */
7
8public function store(Request $request)
9{
10 $validatedData = $request->validate([
11 'title' => 'required|unique:posts|max:255',
12 'body' => 'required',
13 ]);
14
15 // The blog post is valid...
16}
1$rules = [
2 'name' => 'required',
3 'email' => 'required|email',
4 'message' => 'required|max:250',
5 ];
6
7 $customMessages = [
8 'required' => 'The :attribute field is required.'
9 ];
10
11 $this->validate($request, $rules, $customMessages);
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 }
1/**
2 * Store a new blog post.
3 *
4 * @param Request $request
5 * @return Response
6 */
7public function store(Request $request)
8{
9 $validatedData = $request->validate([
10 'title' => 'required|unique:posts|max:255',
11 'body' => 'required',
12 ]);
13
14 // The blog post is valid...
15}
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