模型有一个验证规则:
$rules = [
'uid' => 'required|digits_between:3,9|numeric'
];
$messages = [
'uid.digits_between' => 'Length between 3 and 9',
'uid.numeric' => 'Only numbers',
'*.required' => 'The field is required'
];
如果我在uid
中键入一个字符,则输入2条消息将显示-Length between 3 and 9
和Only numbers
。
在这种情况下,如何仅显示一条消息-Only numbers
,但保持digits_between
规则有效。
答案 0 :(得分:2)
您是否尝试过bail
规则? (https://laravel.com/docs/5.8/validation#quick-writing-the-validation-logic-在首次验证失败时停止)
$rules = [
'uid' => 'bail|required|digits_between:3,9|numeric'
];