mercredi 10 février 2016

Laravel Validation: required_with_all condition always passing

As per laravel validation documentation:

required_with_all:foo,bar,... The field under validation must be present only if all of the other specified fields are present.

Here is my test:

    Route::get('/test/{param}', function($param) {
        $screenRules = array(
            'foo' => 'string',
            'param' => 'required_with_all:foo',

        );

        $validator = Validator::make(array('param' => $param), $screenRules);
        if($validator->fails())
        {
            echo '<pre>';
            print_r($validator->errors());
            echo '</pre>';
            die('Dying now!');
        }
        else
        {
            echo 'All Good!';
            die('Dying now!');
        }
    });

I would expect that since I am not passing foo, this test should fail. But this test passes when I call my url: http://ift.tt/1Xj8KO5

Similarly, if you reverse the role, like so

'param' => 'required_without_all:foo',

and pass foo as input

array('param' => $param, 'foo' => 'bar')

I would expect that since foo is present, you cannot have param as input. But the test still passes.

In both the cases, I should be seeing errors. So what is going on here?


I also know that my validation functions are not wrong, because my other validation works. E.g. add a condition like so:

'param' => 'required_with_all:foo|numeric',

and it sure does throw an error The param must be a number.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire