title: How do I make two required_if validation for my request? Laravel 8
body: <p>I want to make <code>responses.*.answer_id</code> required if <code>responses.*.questiontype == radio</code> or <code>checkbox</code> and <code>responses.*.required == 1</code></p>
  <p>But when I make it like this it is not working:</p>
  <pre><code>$data = request()-&gt;validate([
      'responses.*.answer_id' =&gt; 'required_if:responses.*.questiontype,radio,|required_if:responses.*.required, 1',
      'responses.*.answer_id.*' =&gt;'required_if:responses.*.questiontype,checkbox,|required_if:responses.*.required, 1',
  </code></pre>
  <p>This is what I have in my view:</p>
  <pre><code>@if($question-&gt;questiontype === 'radio')
      &lt;div class=&quot;card-body&quot;&gt;
          @error('responses.'. $key . '.answer_id')
              &lt;small class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/small&gt;
          @enderror
  
          &lt;ul class=&quot;list-group&quot;&gt;
              @foreach($question-&gt;answers as $answer)
              &lt;label for=&quot;answer{{ $answer-&gt;id }}&quot;&gt;
                  &lt;li class=&quot;list-group-item&quot;&gt;
                      &lt;input type=&quot;radio&quot; name=&quot;responses[{{ $key }}][answer_id]&quot; id=&quot;answer{{ $answer-&gt;id }}&quot; 
                      {{ (old('responses.' . $key . '.answer_id')== $answer-&gt;id) ? 'checked' : ''}}
                      class=&quot;mr-2&quot; value=&quot;{{ $answer-&gt;id }}&quot;&gt;
                      {{ $answer-&gt;answer }}
                      &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][question_id]&quot; value=&quot;{{ $question-&gt;id }}&quot;&gt;
                      &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][questiontype]&quot; value=&quot;{{ $question-&gt;questiontype }}&quot;&gt;
                      &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][required]&quot; value=&quot;{{ $question-&gt;required }}&quot;&gt;
                  &lt;/li&gt;
              &lt;/label&gt;
              @endforeach
          &lt;/ul&gt;
      &lt;/div&gt;
  
  @elseif($question-&gt;questiontype === 'text')
      &lt;div class=&quot;card-body&quot;&gt;
          @error('responses.'. $key . '.answer_text')
              &lt;small class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/small&gt;
          @enderror
          &lt;div class=&quot;input-field col s12&quot;&gt;
              &lt;input type=&quot;text&quot; name=&quot;responses[{{ $key }}][answer_text]&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][question_id]&quot; value=&quot;{{ $question-&gt;id }}&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][questiontype]&quot; value=&quot;{{ $question-&gt;questiontype }}&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][required]&quot; value=&quot;{{ $question-&gt;required }}&quot;&gt;
          &lt;label for=&quot;responses[{{ $key }}][answer_text]&quot;&gt;Provide answer&lt;/label&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  @elseif($question-&gt;questiontype === 'textarea')
      &lt;div class=&quot;card-body&quot;&gt;
          @error('responses.'. $key . '.answer_text')
              &lt;small class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/small&gt;
          @enderror
          &lt;div class=&quot;input-field col s12&quot;&gt;
              &lt;textarea name=&quot;responses[{{ $key }}][answer_text]&quot;&gt;&lt;/textarea&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][question_id]&quot; value=&quot;{{ $question-&gt;id }}&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][questiontype]&quot; value=&quot;{{ $question-&gt;questiontype }}&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][required]&quot; value=&quot;{{ $question-&gt;required }}&quot;&gt;
             &lt;label for=&quot;responses[{{ $key }}][answer_text]&quot;&gt;Provide answer&lt;/label&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  @elseif($question-&gt;questiontype === 'checkbox')
      &lt;div class=&quot;card-body&quot;&gt;
          @error('responses.'. $key . '.answer_id')
              &lt;small class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/small&gt;
          @enderror
          &lt;ul class=&quot;list-group&quot;&gt;
          @foreach($question-&gt;answers as $answer)
          &lt;label for=&quot;answer{{ $answer-&gt;id }}&quot;&gt;
              &lt;li class=&quot;list-group-item&quot;&gt;
              &lt;input type=&quot;checkbox&quot; name=&quot;responses[{{ $key }}][answer_id][]&quot; id=&quot;answer{{ $answer-&gt;id }}&quot; 
              {{ (old('responses.' . $key . '.answer_id')== $answer-&gt;id) ? 'checked' : ''}}
              class=&quot;mr-2&quot; value=&quot;{{ $answer-&gt;id }}&quot;&gt;
              {{ $answer-&gt;answer }}
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][question_id]&quot; value=&quot;{{ $question-&gt;id }}&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][questiontype]&quot; value=&quot;{{ $question-&gt;questiontype }}&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;responses[{{ $key }}][required]&quot; value=&quot;{{ $question-&gt;required }}&quot;&gt;
              &lt;/li&gt;
          &lt;/label&gt;
          @endforeach
          &lt;/ul&gt;
      &lt;/div&gt;
  @endif      
  &lt;/div&gt;
  @endforeach
  </code></pre>
  <p>I would like to require the <code>answer_id</code> for radio and checkbox <code>questiontypes</code> and if the required hidden field is equal to 1.</p>