0
votes

In my project, i use lumen 5.8(I create my project by "lumen new test" command ). And i use validation's(Illuminate\Support\Facades\Validator) required_without to validate my request parameters. But "required_without " didnot work correctly.

$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、if request data is: { "Field_1": 1 }

--actually reuslt: "Validate parameters fail. [Error] {"Field_2":["The field 2 field is required when field 1 is not present."]}

--expected reuslt: no error, because Field_1 field is set to 1, Field_2 is no need to be set.

2、if request data is: { "Field_2": 2 }

--actually reuslt: Validate parameters fail. [Error] {"Field_1":["The field 1 field is required when field 2 is not present."]}

--expected reuslt: no error

3、if request data is: { "Field_1": 1, "Field_2": 2 }

--actually reuslt: no error

--expected reuslt: no error

1
This looks like something you should file as a bug request on the lumen project. - Andrew Carr

1 Answers

0
votes

I believe you should file this as a bug in the Lumen source project.

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