1public function store(Request $request)
2{
3 $validator = Validator::make($request->all(), [
4 'title' => 'bail|required|max:255',
5 'body' => 'required',
6 ]);
7
8 // Check validation failure
9 if ($validator->fails()) {
10 // [...]
11
12 foreach($validator->messages()->getMessages() as $field_name => $messages) {
13
14 // Go through each message for this field.
15 foreach($messages AS $message) {
16 echo '***********'.$message.'***********<br>';
17 }
18 }
19 }
20
21 // Check validation success
22 if ($validator->passes()) {
23 // [...]
24 }
25
26 // Retrieve errors message bag
27 $errors = $validator->errors();
28}