remove rules and try if it is passing you have to change rules
return [
'guest.*.sleeps' => 'required|not_in:0',
'guest.*.comments' => 'max:300',
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a form and inputs are inside loop. Each inputs are validating using Laravel validation array method. At present I am submitted name as guest[{{ $cart->_id }}][sleeps] guest[{{ $cart->_id }}][comments].
Validation is working fine for each input. But data is not submitted in to controller page. After submit the form, page is redirect back. I am getting http 302 status.
If I change name like name="sleeps[]" and name="comments[]" the data is posting in to controller. Any help would be appreciated.
routes.php
Route::post('/cart/store', 'CartController@store')->name('cart.store');
cart.blade.php
<form action="{{ route('cart.store') }}" method="post">
{{ csrf_field() }}
<div class="panel panel-default text-left panel-booking1 panel-default-booking1">
@forelse($carts as $key => $cart)
<div class="col-sm-4 col-sm-4-booking1 form-group {{ $errors->has('guest.*.sleeps') ? ' has-error' : '' }}">
<label>Sleep(s)</label>
<select class="form-control form-control-booking1 jsBookCalSleep" name="guest[{{ $cart->_id }}][sleeps]">
<option value="">Choose Sleep(s)</option>
@for($i = 1; $i <= 30; $i++)
<option value="{{ $i }}" @if($i == $cart->sleeps) selected @endif>{{ $i }}</option>
@endfor
</select>
@if ($errors->has('guest.*.sleeps'))
<span class="help-block"><strong>{{ $errors->first('guest.*.sleeps') }}</strong></span>
@endif
</div>
<div class="col-sm-4 col-sm-4-f-booking1 comment-booking1 col-sm-4-booking1">
<div class="form-group {{ $errors->has($inputComments) ? ' has-error' : '' }}">
<textarea id="comments_{{ $cart->_id }}" name="guest[{{ $cart->_id }}][comments]" class="form-control" rows="3" maxlength="300" placeholder="Comment...">{{ old($inputComments) }}</textarea>
@if ($errors->has($inputComments))
<span class="help-block"><strong>{{ $errors->first($inputComments) }}</strong></span>
@endif
</div>
</div>
@empty
<p>No bookings in your cart</p>
@endforelse
<div>
<div id="btn-ground-2-booking1">
<button type="submit" class="btn btn-default-booking1 btn-default btn-sm btn-details btn-details-booking1"><span class="glyphicon glyphicon-credit-card" style="font-size: 14px;" aria-hidden="true"></span> Payment</button>
</div>
</div>
</form>
CartRequest.php
public function rules()
{
return [
'guest.*.sleeps' => 'required|not_in:0',
'guest.*.comments' => 'max:300',
];
}
CartController.php
public function store(CartRequest $request)
{
dd($request->all());
}
Chrome Console
General
Request URL: https://frontend.test/cart/store
Request Method: POST
Status Code: 302
Remote Address: 192.168.10.10:443
Referrer Policy: no-referrer-when-downgrade
Request Header
:authority: frontend.test
:method: POST
:path: /cart/store
:scheme: https
Form Data
_token: SBpj6Cf87TyDmUeqM1N8MoREmBwG7MdzCsPR9BHr
guest[5ac5e2e09a892042bb7b2d59][sleeps]: 1
guest[5ac5e2e09a892042bb7b2d59][comments]:
guest[5ac5e2f49a89205a311248ef][sleeps]: 1
guest[5ac5e2f49a89205a311248ef][comments]:
Please or to participate in this conversation.