0

I know how do make custom validation in Laravel. But how do I create a validation rule that a input value has to be greater than other input value? (I know how to do it within the controller, but how do I do it using Validator class in Laravel?)

1 Answer 1

1

I would extend Laravel Validator class and add a new method:

protected function validateGreaterThanInput($attribute, $value, $parameters){
    return $this->getSize($attribute) > $this->getSize($parameters[0]); 
}

Then in your validation rules you can use something like:

$rules = [
    'input' => 'greaterThanInput:secondInput'
];

I think that should do the trick.

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.