lumen5.8验证程序的“ required_without”工作异常

时间:2019-05-26 10:09:33

标签: validation lumen php-7.1

在我的项目中,我使用流明5.8(我通过“ lumen new test”命令创建了我的项目)。而且我使用验证的(Illuminate \ Support \ Facades \ Validator)required_without来验证我的请求参数。但是“ required_without”无法正常工作。

$fields = [
    'Field_1'     =>  'required_without: Field_2 | int',
    'Field_2'     =>  'required_without: Field_1 | int',
];

$validator = Validator::make($args, $fields);
if ($validator->fails()) {
    echo "Validate parameters fail. [Error] " . json_encode($validator->errors()) . "\n";
}

1,如果请求数据为: {   “ Field_1”:1 }

-实际上是重用: “验证参数失败。[错误] {” Field_2“:[”当字段1不存在时,字段2字段是必需的。“]}

-预期重用:没有错误,因为Field_1字段设置为1,因此不需要设置Field_2。

2,请求数据为: {   “ Field_2”:2 }

-实际上是重用: 验证参数失败。 [错误] {“ Field_1”:[“当不存在字段2时,字段1字段是必需的。”]}

-预期重用:没有错误

3,请求数据为: {   “ Field_1”:1   “ Field_2”:2 }

-实际上是重用:没有错误

-预期重用:没有错误

1 个答案:

答案 0 :(得分:0)

我相信您应该将此文件作为流明源项目中的错误提交。

https://github.com/laravel/lumen-framework/issues