I have the following array input fields. They are optional fields, however I want to use the required_if validation rule so that if the user enters a question they must select an expected answer as well. If user selects an expected answer then they should also include a question.
<input type="text" name="questions[0].question_text">
@if ($errors->has('questions[0].question_text')) {{ $errors->first('questions[0].question_text') }} @endif
<select name="questions[0].expected_answer">
<option value="">Please Select</option>
<option selected="selected" value="true">Yes</option>
<option value="false">No</option>
</select>
@if ($errors->has('questions[0].expected_answer')) {{ $errors->first('questions[0].expected_answer') }} @endif
I've tried the following but it doesn't work:
'questions.0.question_text' => 'required_if:questions.0.expected_answer,true,false',
'questions.0.expected_answer' => 'required_if:questions.0.question_text,null'
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire