Kaustubh
2 years ago

how to pass variable in validation rule

Posted 2 years ago by Kaustubh

Hi guys,

I want to validate text field if Commission amount is less than 4.5% on Salary

<input type="text" id="salary" name="salary">
<input type="text" id="commission" name="commission" placeholder="Amt should be >= 4.5% on salary">

public function hrCJPsave(Request $req)
{  
     $salary => REQUEST('salary');
     $commission = $salary*4.5/100;

    $input = $req->all();
    $validator = Validator::make($input, [
        'salary'            =>  'required|max:2',
        'commission'        =>  'required|min:$commission'            
    ]);
}

How can i pass variable in validator

Please sign in or create an account to participate in this conversation.