对数组子元素进行验证时验证结果返回异常
trising opened this issue · comments
奶嘴 commented
验证规则:
[
['goods_id', 'array', 'list', 'msg' => '商品id数组为空或不合法'],
['goods_id.*', 'integer', 'msg' => '商品分类id必须是一串数字']
]
验证的数据:
[
"goods_id" => [
1144181460261978556, 114418146, 1144
]
]
返回结果:商品分类id必须是一串数字
Inhere commented
这里规则写错了。
[
['goods_id', 'list', 'msg' => '商品id数组为空或不合法'],
['goods_id.*', 'each', 'integer', 'msg' => '商品分类id必须是一串数字']
]
- 只能写一个验证器
'array', 'list'
同时写也只有 array 生效了。
这里推荐写
list
,list 已经是包含了array验证的,先是array才会是list
'goods_id.*'
取到的是个 int list 数组,直接对它验证 integer,是没法通过的
使用
each
验证数组里的每个值 为integer
。
'goods_id.0', 'integer'
这样指明某一个值验证 int 是可以的。
奶嘴 commented
这里规则写错了。
[ ['goods_id', 'list', 'msg' => '商品id数组为空或不合法'], ['goods_id.*', 'each', 'integer', 'msg' => '商品分类id必须是一串数字'] ]
- 只能写一个验证器
'array', 'list'
同时写也只有 array 生效了。这里推荐写
list
,list 已经是包含了array验证的,先是array才会是list
'goods_id.*'
取到的是个 int list 数组,直接对它验证 integer,是没法通过的使用
each
验证数组里的每个值 为integer
。
'goods_id.0', 'integer'
这样指明某一个值验证 int 是可以的。
sorry,我这边看文档没看仔细。已经ok了