【问题标题】:lumen5.8 Validator's "required_without" work unexpectedlylumen5.8 Validator 的“required_without”意外工作
【发布时间】:2019-10-12 05:36:01
【问题描述】:

在我的项目中,我使用 lumen 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、如果请求数据是: { “字段_1”:1 }

--实际上是这样的: "验证参数失败。[Error] {"Field_2":["当字段 1 不存在时,字段 2 字段是必需的。"]}

--预期结果:没有错误,因为Field_1字段设置为1,所以Field_2不需要设置。

2、如果请求数据是: { “字段_2”:2 }

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

--预期结果:没有错误

3、如果请求数据是: { “字段_1”:1, “字段_2”:2 }

--实际上reuslt:没有错误

--预期结果:没有错误

【问题讨论】:

  • 这看起来像是你应该在 lumen 项目中提交错误请求。

标签: validation lumen php-7.1


【解决方案1】:

我认为您应该将此作为 Lumen 源项目中的错误提交。

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

【讨论】:

    猜你喜欢
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    相关资源
    最近更新 更多