我的表单是这样的:-
有些字段是数组,例如institute[]
,degree[]
等。
我正在使用Laravel表单验证,但是我无法获得自定义的验证消息。这是我的代码:-
$validationCondition = array(
"institute" => "required|array|min:1",
"institute.*" => "required|string|distinct|min:3",
"degree" => "required|array|min:1",
"degree.*" => "required|string|distinct|min:3",
); // validation condition
$validationMessages = array(
'institute.required' => 'Please provide at least one institute record',
'institute.min' => 'Please provide at least one institute record',
'institute.*.string' => 'Institute name should be string',
'institute.*.distinct' => 'Institute name should be distinct',
'institute.*.min' => 'Institute name should be three characters at least',
'degree.required' => 'Please provide at least one institute record',
'degree.min' => 'Please provide at least one degree record',
'degree.*.string' => 'Degree name should be string',
'degree.*.distinct' => 'Degree name should be distinct',
'degree.*.min' => 'Degree name should be three characters at least',
); // validation message
$Validator = Validator::make($request->all(), $validationCondition, $validationMessages);
但是,当我仅提交一组带有学院和学位空白的表格输入时,我会以这种方式收到消息
The institute.0 field is required.
The degree.0 field is required.
我想在缺少记录1(索引0)时显示“请提供记录1的学位数据”。
我该怎么做?