有一个请求,其结构如下:
{
"anything": false,
"specifications": [
{
"nomenclature_id": null,
"nomenclature_name": "Деревянный камень",
"anything": true,
},
{
"nomenclature_id": 3, // !!!
"nomenclature_name": null,
"anything": true,
},
]
}
有必要描述联合现场验证的规则
specifications.*.nomenclature_id
specifications.*.nomenclature_name
以这样一种方式,其中一个必须为 null,另一个 !== null,同时:
如果 nomenclature_id !== null,则检查是否存在:nomenclatures,id
如果 nomenclature_name !== null,则检查字符串
我使用 required_if、exclusion_if 等规则尝试了不同的选项,有时等等。但没有达到预期的效果。很明显,我可以聪明地从控制器中删除此检查,并用代码描述它,但恕我直言,如果可以使用框架的内置工具完成某些操作,那么应该使用框架的工具来完成。
PHP 8.2
拉拉维尔 10
