Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

doproj123's avatar

validate array with inputs (text) not work

Hi. I have problem with validate html input array. I have something like this:

<td colspan="2">
 <div class="form-check">
{!! Form::checkbox('car', null, false,  ['class'=>'form-check-input']); !!}
<label class="form-check-label" for="defaultCheck1">Car</label>
</div>
 </td>
<td>
<div class="form-inline">
<label class="form-check-label" for="defaultCheck1">1.</label>
<input class="form-control form-control-sm" style="width: 98%" type="text" name="new[]"/>
</div>
 <div class="form-inline">
 <label class="form-check-label" for="defaultCheck1">2.</label>
  <input class="form-control form-control-sm" style="width: 98%" type="text" name="new[]"/>
</div>
</td>
...
$request->validate([               
                'new' => ['required_if:car,on', 'array', 'min:1'],
            ]

This validate not work. When Checkbox is not selected if nothing happen. Is this correct way to valdiate array with inputs (type text)?

0 likes
5 replies
bugsysha's avatar

I've never tried name="new[]" for input field. For checkbox it works. What happens if you remove 2. input and just put name="new" for the first input?

doproj123's avatar

I can't remove 2 input. Tell the truth I need more than 2 inputs (about 6) and I really believe it should be possible to do something like this.

bugsysha's avatar

You are right, you can do input with name="something[]". Have you checked that you are submitting this form to correct route, also that route is correct? Post form tag attributes or whole form and routes and code in that controller method.

Snapey's avatar

use new.* in your validation rule

bugsysha's avatar

@snapey that is wrong based on what he posted since he expects new to be array and have minimum 1 item in it.

Please or to participate in this conversation.