简体   繁体   English

Laravel 4.2验证输入必须大于其他输入

[英]Laravel 4.2 validation input has to be greater than other input

I know how do make custom validation in Laravel. 我知道如何在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?) (我知道如何在控制器中执行此操作,但是如何使用Laravel中的Validator类执行操作?)

I would extend Laravel Validator class and add a new method: 我将扩展Laravel Validator类并添加一个新方法:

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. 我认为应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM