laravel如何只验证内部数组之间的不同规则

sy5wg1nm  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(233)
'variants' => ['nullable', 'array'],
'variants.*.name' => ['required', 'string'],
'variants.*.options' => ['required', 'array', 'min:1'],
'variants.*.options.*.code' => ['required', 'string', 'distinct'],

我在上面有一个验证规则,我试图实现的是,只有内部数组之间的值是不同的,但不知怎的,我在输入时遇到了这样的错误
输入:

{
   variants: [
       {
           name: "outer array 1",
           options: [
               {
                  code: "A"
               },
               {
                  code: "B"
               }
           ]
       },
       {
           name: "outer array 2",
           options: [
               {
                  code: "A"
               },
           ]
       }
   ]
}

结果:

"error": {
        "variants.0.options.0.code": [
            "The variants.0.options.0.code field has a duplicate value."
        ],
        "variants.1.options.0.code": [
            "The variants.1.options.0.code field has a duplicate value."
        ]
    }

问:有没有办法只区分内部数组而不是每个数组?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题