1 @if ($errors->any())
2 @foreach ($errors->all() as $error)
3 <div>{{$error}}</div>
4 @endforeach
5 @endif
6
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$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);
12