Php Laravel 5.6中的验证

Php Laravel 5.6中的验证,php,validation,laravel-5.6,Php,Validation,Laravel 5.6,这个问题已经问过了,但这并不能解决我的问题 我尝试在我的laravel项目中使用验证。但它不起作用这是我的代码 $rules = array( 'coupon_title' => 'max:10', 'coupon_type_id' => 'numaric', 'expiry_start_date' => 'required|before_or_equal:expiry_end_date', 'expiry

这个问题已经问过了,但这并不能解决我的问题

我尝试在我的
laravel项目中使用验证。但它不起作用这是我的代码

$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);
}
仅在我的代码中
到期\u开始\u日期
字段已验证。但未验证
优惠券标题
优惠券类型\u id
字段


您需要将拼写
numeric
更正为
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'
];

您在优惠券附近有一个很小的打字错误(类型id:是“数字”,而不是“数字”)优惠券标题和优惠券类型id是否允许为空?@Virginia:Yes#优惠券标题允许为空值可以添加HTML部分/使用这四个变量的视图(优惠券标题、优惠券类型、有效期、有效期开始日期、有效期结束日期?我想这会更容易发现问题。@Virginia:我设置了
优惠券标题
Null是看到这张图片了吗?但我怀疑是否希望数据库中的字段将Null改为yes?@RameshS是您需要在mysql中将列设为Null