Search code examples
laravel-5laravel-5.8laravel-validation

How i can compare Two input values at the time of validation


when I submit the form, I want to compare two input values at the time of validation in Controller store function

array(
'name' => 'required',
'password' => 'required|min:8',
'email' => 'required|email|unique:users',
'rule'=>'input1'<'input2',
)

Solution

  • I assume your rule property is not really an input field on the form or data. Because if rule is a property, like email, then I don't know what you want to validate it against. (rule is only valid if input1 is smaller than input2?)

    Maybe you actually want to validate the input1 attribute like this:

    array(
        'name' => 'required',
        'password' => 'required|min:8',
        'email' => 'required|email|unique:users',
        'input1'=> 'lt:input2',
    )
    

    Do mind that input1 and input2 must be of the same type. See: https://laravel.com/docs/5.8/validation#rule-lt