【发布时间】:2018-12-11 08:01:30
【问题描述】:
这个问题已经问过了,但这并没有解决我的问题。
我尝试在我的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字段经过验证。但coupon_title和coupon_type_id字段未验证。
【问题讨论】:
-
您在 coupon_type_id 附近有一个小错字:它是 'numeric',而不是 'numaric' ;)
-
coupon_title 和 coupon_type_id 是否允许为空?
-
@Virginia:Yes #coupon_title 允许空值
-
您能否在使用这四个变量(coupon_title、coupon_type_id、expiry_start_date、expiry_end_date)的地方添加 HTML 部分/视图?我认为这可能更容易发现问题。
-
@Virginia:我设置了
coupon_titleNull 是的,看这张图片imgur.com/a/QLtZIW2
标签: php validation laravel-5.6