0

Newbie here. Can anyone help me about getting the parameter in my custom validation.

Here is my validation rule :

['materials.*.receive_quantity' => 'lessthan:materials.*.quantity']

Here is my custom validation :

Validator::extend('lessthan', function ($attribute, $value, $parameters, $validator) { return $value <= $parameters[0]; });

When i dd($parameters) it return a string 'materials.*.quantity'. TIA.

1 Answer 1

2

First, you'll need a 5.4.18 release. Then, try this code:

Validator::extendDependent('lessthan', function ($attribute, $value, $parameters, $validator) {
    return $value <= array_get($validator->getData(), $parameters[0]);
});

And you may look at this pull request for more explanations and examples: PR#18564

P.S. And may be this is a typo in your code: your rule name is "lessthan", but you use the "<=" operator instead of "<".

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.