以下是流明的服务器端验证:
$rules = array(
'prog_code' => 'required',
'payer_id' => 'required',
);
$validator = \Validator::make($post, $rules);
if (!$validator->fails()) {
try {
// Start Logic Here
} catch (\Exception $e) {
}
} else {
$errors = $validator->errors();
return response()->json($errors->all());
}
并返回如下错误:
[
"The prog code field is required.",
"The payer id field is required.",
]
但问题是我如何映射哪个字段的错误,因为我想在特定文本字段下面显示错误。
我们可以自定义如下错误:
[
[prog_code] => "The prog code field is required.",
[payer_id] => "The payer id field is required.",
]
答案 0 :(得分:1)
我实现相同反应的方式是:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN; // to get rid of empty section header
}
答案 1 :(得分:0)
如果您转储$errors
变量,则会出现一系列错误,例如您的目标:
ViewErrorBag {#406
#bags: array:1 [
"default" => MessageBag {#407
#messages: array:1 [
"pin" => array:1 [
0 => "The Programming Code is required Sir!"
]
]
#format: ":message"
}
]
}
当出现错误时,验证器会注入 $errors
变量