这个问题已经问过了,但这并不能解决我的问题。
我已经尝试在我的laravel project
中使用验证。但它不工作这是我的代码
$rules = array(
'coupon_title' => 'max:10',
'coupon_type_id' => 'numaric',
'expiry_start_date' => 'required|before_or_equal:expiry_end_date',
'expiry_end_date' => 'required',
);
$messages = [
'before_or_equal' => 'The :attribute must be smaller than the End Date',
'before' => 'The :attribute must be Greater than the Interview Start Date',
'after' => 'The :attribute must be Greater than the Interview End Date',
'after_or_equal' => 'The :attribute must be Greater than the Start Time',
//'max' => 'asdasd'
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails())
{
$messages = $validator->messages();
return response()->json(['message'=>$messages],401);
}
在我的代码中,只有
expiry_start_date
字段经过验证。但CCD_ 3和CCD_。
您需要将numaric
拼写为numeric
,并在验证规则中添加nullable
关键字
'coupon_title' => 'string|max:10|nullable',
'coupon_type_id' => 'numeric',
还可以为numeric
和max
添加自定义消息
$messages = [
'before_or_equal' => 'The :attribute must be smaller than the End Date',
'before' => 'The :attribute must be Greater than the Interview Start Date',
'after' => 'The :attribute must be Greater than the Interview End Date',
'after_or_equal' => 'The :attribute must be Greater than the Start Time',
'max' => 'The :attribute has crossed the limit',
'numeric' => 'The :attribute must have numeric value'
];