title: Laravel Validation Rules If Value Exists in Another Field Array
body: <p>I am working in Laravel 5.4 and I have a slightly specific validation rules need but I think this should be easily doable without having to extend the class. Just not sure how to make this work..</p>
  
  <p>What I would like to do is to make the <code>'music_instrument'</code> form field mandatory if <code>program</code> array contains <code>'Music'</code>.</p>
  
  <p>I found this thread <a href="https://stackoverflow.com/questions/40302105/how-to-set-require-if-value-is-chosen-in-another-multiple-choice-field-in-valida">How to set require if value is chosen in another multiple choice field in validation of laravel?</a> but it is not a solution (because it never got resolved in the first place) and the reason it doesn't work is because the submitted array indexes aren't constant (not selected check boxes aren't considered in indexing the submission result...)</p>
  
  <p>My case looks like this:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
      &lt;fieldset&gt;
  
          &lt;input name="program[]" value="Anthropology" type="checkbox"&gt;Anthropology
          &lt;input name="program[]" value="Biology"      type="checkbox"&gt;Biology
          &lt;input name="program[]" value="Chemistry"    type="checkbox"&gt;Chemistry
          &lt;input name="program[]" value="Music"        type="checkbox"&gt;Music
          &lt;input name="program[]" value="Philosophy"   type="checkbox"&gt;Philosophy
          &lt;input name="program[]" value="Zombies"      type="checkbox"&gt;Zombies
  
          &lt;input name="music_instrument" type="text" value""&gt;
  
          &lt;button type="submit"&gt;Submit&lt;/button&gt;
  
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>If I select some of the options from the list of check boxes I can potentially have this result in my <code>$request</code> values</p>
  
  <pre><code>[program] =&gt; Array
      (
          [0] =&gt; Anthropology
          [1] =&gt; Biology
          [2] =&gt; Music
          [3] =&gt; Philosophy
      )
  
  [music_instrument] =&gt; 'Guitar'
  </code></pre>
  
  <p>Looking at validation rules here: <a href="https://laravel.com/docs/5.4/validation#available-validation-rules" rel="noreferrer">https://laravel.com/docs/5.4/validation#available-validation-rules</a> I think something like his should work but i am literally getting nothing:</p>
  
  <pre><code>  $validator = Validator::make($request-&gt;all(),[
          'program'           =&gt; 'required',
          'music_instrument'  =&gt; 'required_if:program,in:Music'
    ]);
  </code></pre>
  
  <p>I was hoping this would work too but no luck:</p>
  
  <pre><code>'music_instrument'  =&gt; 'required_if:program,in_array:Music',
  </code></pre>
  
  <p>Thoughts? Suggestions?</p>
  
  <p>Thank you!</p>