I have this validation rules and i appended some custom messages for those validations.
$this->validate($request, [
'name'=>'required',
'departments.*.name'=>'required',
'departments.*.sections.*.name'=>'required',
],[
'name.required'=>'The division name field is required.',
'departments.*.name.required'=>'The department name field is required.',
'departments.*.sections.*.name.required'=>'The section name field is required.',
]);
Screenshot of my view:
Here you can see, the empty section input field showing error message
"The department name field is required."
But it should be show
"The section name field is required."
What am i missing?
Note: i am printing the first index of all fields error messages
Its replacing the error messages from departments.*.sections.*.name.required
You should add child dimension errors before parent fields
try to use this:
$this->validate($request, [
'name'=>'required',
'departments.*.name'=>'required',
'departments.*.sections.*.name'=>'required',
],[
'name.required'=>'The division name field is required.',
'departments.*.sections.*.name.required'=>'The section name field is required.',
'departments.*.name.required'=>'The department name field is required.',
]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.