I work in Laravel 5.7, I have a Model Locations, a controller LocationsController, and since there are so few data that this model will have (and its respective table in the database) I have decided to make their respective crud in the same index through modal windows, the problem is that by bringing all the data with a foreach, the variable that I use to bring this data remains with the information of the last object that was shown, so when using the edit or destroy method from the same index, only allows me to delete and edit the last object in the table
Table showing the data .
<tbody>
@foreach($locations as $location)
<tr>
<td>{{$location->id}}</td>
<td>{{$location->nombre}}</td>
<td><button onclick="window.location='./locations/{{$location->id}}/edit'" class="btn btn-primary">Editar</button></td>
<td><button onclick="document.getElementById('modalConfir').style.display='block'" class="btn btn-danger">Eliminar</button></td>
</tr>
@endforeach
</tbody>
Delete button that is inside the modal window:
{!! Form::open(['route' => ['locations.destroy', $location->id], 'method' => 'DELETE']) !!}
{!! Form::submit('Eliminar', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
Is there any way to make this work correctly?