I have a page that displays records from the database and two buttons with the addition of a new record and editing using the bootstrap modal in Laravel 5.8
. When I add a new record to the database, everything works. The problem is when editing a record it only changes the first record because it does not transfer the remaining id it always shows only the first id. As I display the records with each button edit, I display the id of the record and everything shows correctly but after pressing the button edit does not provide the id. In the form I use the following code. source: [a link]https://github.com/page4me/transport
@foreach($cars as $car)
@if(($car->status)==1)
<tr>
<td class="text-center">{{$i++}}</td>
<td>{{$car->rodzaj_poj}}<br /><strong> {{$car->marka}} </strong></td>
<td class="text-center">{{$car->nr_rej}}</td>
<td class="text-center">{{$car->nr_vin}}</td>
<td class="text-center">{{$car->dmc}} kg</td>
<td class="text-center">{{$car->wlasnosc}}</td>
<td class="text-center">wprowadzono <br />{{$car->data_wpr}} r.</td>
<td class="text-center" colspan="2">
{{$cid =$car->id}}
<button data-toggle="modal" data-idcar="{{$car->id}}" data-nr_rej="{{$car->nr_rej}}" data-marka="{{$car->marka}}" data-nr_vin="{{$car->nr_vin}}" data-wlasnosc="{{$car->wlasnosc}}" data-data_wpr="{{$car->data_wpr}}" data-dmc="{{$car->dmc}}" data-rodzaj_poj="{{$car->rodzaj_poj}}" data-target="#editModal" role="button" class="btn btn-success btn-sm" alt="Edycja" ><i class="fa fa-edit"></i></button>
<a href="#" role="button" class="btn btn-danger btn-sm">Wycofaj</a>
<!-- edit modal -->
<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content text-left">
<div class="modal-header bg-success">
<div class="card-header bg-success text-light" >
Edycja pojazdu przedsiębiorcy o -
<span style="color:#000;font-size:15px;"> Nr licencji / zezwolenia:
@foreach($dok as $dk)
{{ $dk->nr_dok }}
</span><span style="color: #fff;font-size:15px;">wydano dn. {{ $dk->data_wyd}} r.</span>
@endforeach
</div>
<button type="button" class="close text-light" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
ID: {{$cid =$car->id}}
<!-- Form edit car -->
<form method="post" action="{{ route('pojazdy.update', $cid ) }}">
<div class="row">
@csrf
@method('PATCH')
<div class="col-md-12 form-group">
<label for="nr_rej"><strong>Numer rejestracyjny:</strong></label>
<input type="text" class="form-control" name="nr_rej" id="nr_rej" value="{{$car->nr_rej}}"/>
</div>
</div>
It always displays only the first id even though it is displayed in the foreach loop. next to buttons edit correctly shows id and when using in action = "{{route ('vehicle.update', $ car-> id)}}"
there is already a problem