title: Laravel Validation: Custom rules on arrays (before_if)
body: <p>I am trying to write a custom before_if rule that mirrors the required_if rule. What I am trying to accomplish is making sure that the "primary" name on an account is not a minor (18+ years), but I am not quiet sure how to deal with this because I am looking at an array.</p>
  
  <p>My rule looks like this</p>
  
  <pre><code>'names.*.birthdate' =&gt; 'required|date|before_if:-18 years,names.*.type,0' // Type 0 is primary name
  </code></pre>
  
  <p>However, I am not quite sure what to do in my extend logic. Specifically, I am not sure how to find the index of the current name I am on. I know this is possible because I already do this multiple times using required_if.</p>
  
  <pre><code>Validator::extend('before_if', function($attribute, $value, $parameters, $validator){
          // Not sure how to find the current index  
  });
  </code></pre>