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<!-- /resources/views/post/create.blade.php -->
2
3<h1>Create Post</h1>
4
5@if ($errors->any())
6 <div class="alert alert-danger">
7 <ul>
8 @foreach ($errors->all() as $error)
9 <li>{{ $error }}</li>
10 @endforeach
11 </ul>
12 </div>
13@endif
14
15<!-- Create Post Form -->
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}
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