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}
19
2
3If it has worked for you before then you should check if you have messages defined in the app\lang\en\validation.php or by chance you have changed the locale of the app and have not defined the messages for it. There are many possibilities.