@devsam247
Look at the output you just sent:
array:6 [▼
0 => array:1 [▼
"service" => "Web Design" ]
1 => array:1 [▼
"amount" => "4500.00" ]
2 => array:1 [▼
"description" => "PHP, HTML, CSS, JavaScript, React" ]
3 => array:1 [▼
"service" => "Graphic Design" ]
4 => array:1 [▼
"amount" => "2500.00" ]
5 => array:1 [▼
"description" => "Photoshop, CorelDraw, InDesign, Figma, Illustrator" ]
]
You have 6 items, each one with only one field.
- Field with index 0 only has
service
- Field with index 1 only has
amount
- Field with index 2 only has
description
- Field with index 3 only has
service
- Field with index 4 only has
amount
- Field with index 5 only has
description
You need to add an index to the field names to group each record.
You probably have your blade fields inside an foreach, use its $loop->index:
<div class="row">
<div class="col-md-12 service-group">
<div class="row">
<div class="form-group mb-3 col-md-6">
<label class="form-label" for="service-{{ $loop->index }}">
Service
</label>
<select class="form-select" required
name="items[{{ $loop->index }}][service]"
id="service-{{ $loop->index }}">
<option value="" disabled selected>Select your option</option>
@foreach ($services as $service)
<option value="{{$service->service_name}}"
data-id="{{$service->amount}}">
{{$service->service_name}}
</option>
@endforeach
</select>
</div>
<div class="form-group mb-3 col-md-6">
<label class="form-label" for="amount-{{ $loop->index }}">
Amount
</label>
<input type="text" class="form-control" readonly required
name="items[{{ $loop->index }}][amount]"
id="amount-{{ $loop->index }}"
placeholder="Amount">
</div>
<div class="form-group mb-3 col-md-12">
<label class="form-label" for="description-{{ $loop->index }}">
Description
</label>
<textarea class="form-control" rows="6" required
name="items[{{ $loop->index }}][description]"
id="description-{{ $loop->index }}"
placeholder="Description.."></textarea>
</div>
</div>
</div>
</div>
Note I added $loop->index also to the ids, as ids should be unique. To see the benefit of it, click on a label text and see if the input is selected.
reference: https://laravel.com/docs/9.x/blade#the-loop-variable