0

I'm trying to add a custom rule for validator, but it's not working at all, the function is not even called. I took this from documentation(https://laravel.com/docs/5.4/validation#custom-validation-rules):

In AppServiceProvider::boot I have this:

Validator::extend('foo', function ($attribute, $value, $parameters, $validator) {
   return false;
});

and In my controller I have this:

$validator = Validator::make($request->all(), [
    'myField' => 'foo',
]);

The validator doesn't fail. What am I doing wrong?

1 Answer 1

2

Fixed it. My json was wrong and if input value is null(or empty) then custom Validator::extend rules won't be checked. So solution would be

Validator::extendImplicit('foo', function ($attribute, $value, $parameters, $validator) {
    return $value == 'foo';
});

or $request field that isn't empty

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.