title: Passing variable to validator, Laravel
body: <p>I have created a custom validator in <code>AppSeriveProvider.php</code> with code:-</p>
  
  <pre><code>Validator::extend('less_than', function($attribute, $value, $parameters, $validator) {
      $max_field = $parameters[0];
      $data = $validator-&gt;getData();
      $max_value = 100;
      return $value &lt; $max_value;
  });
  
  Validator::replacer('less_than', function($message, $attribute, $rule, $parameters) {
      return str_replace(':field', $parameters[0], $message);
  });
  </code></pre>
  
  <p>And my controller have this piece of code</p>
  
  <pre><code>$messages = [
      'bid.required' =&gt; 'Please enter the amount',
      'bid.less_than' =&gt; 'Insufficient balance',
  ];
  $balance = 100;
  $v = Validator::make($request-&gt;all(), [
           'bid' =&gt; 'required|less_than:$balance',
       ],$messages);
  
  if ($v-&gt;fails()) {
      return redirect('newgame')
             -&gt;withErrors($v)
             -&gt;withInput();
      }else {
              echo "Success"
       }
  </code></pre>
  
  <p>I have to send balance variable to the validator and in the validator function I have to set $max_value (which currently have 100) to the value in $balance. </p>
  
  <p>After searching in directories and looking to the code I cannot understand   that what are the contents of <code>$parameters</code> variable because its 0 index is referred in max_field, how <code>$validator-&gt;getData()</code> works? and how <code>$max_value</code> is getting its value.</p>
  
  <p>Please someone explain me all this or comment the link to respective problems.And help in solving this big problem.</p>