I have a table in which to each row I pass some variables through a foreach.
And when I give 'Delete' a modal opens, that has the first value of the table, it does not matter if I click on the delete button of the row with ID 5, that I will get the value of ID 1 .
The code is this:
<tbody>
@foreach ($admins as $key => $admin)
<tr>
<td class="idadmin tdcenter"><p id="margindata" class="tdmenuadmin">{{$admin->id}}</p></td>
<td class="nameadmin"><p id="margindata" class="tdmenuadmin">{{$admin->name}}</p></td>
<td class="emailadmin"><p id="margindata" class="tdmenuadmin">{{$admin->email}}</p></td>
<td class="actionsadmin tdmenuadmin">
<button type="button" class="btn btn-danger btn-sm deletemenuadmin" data-toggle="modal" data-target="#formdeleteadmin" id="margindata">Delete</button>
<div id="formdeleteadmin" class="modal fade" role="dialog"> <!-- DIV TO SHOW THE CREATE PROJECT FORM 1 START HERE-->
<div class="modal-dialog" style="background-color:#23517F;">
<div class="modal-content" style="background-color:#23517F;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" style="color:black;">{{$admin->id}}¿Estas seguro de borrar al administrador?</h4>
</div>
<div class="modal-body">
<div class="col-sm-6">
<a href="{{ route('admin.admins') }}" class="btn btn-danger btn-block">No</a>
</div>
<div class="col-sm-6">
<form method="POST" action="{{route('admin.admins.destroy',$admin->id)}}">
<input type="submit" value="Si" class="btn btn-danger btn-block">
<input type="hidden" name="_token" value="{{Session::token()}}">
{{method_field('DELETE')}}
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="closemodal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
@endforeach
</tbody>
When I give the Delete it shows me this modal: (it's clipped)
And if I give to if it goes to the route that indicates the code and executes the function of the controller, the function is this:
public function destroyAdmin($id) //Eliminar la informacion de un admin
{
$admin = Admin::find($id);
$admin->delete();
Session::flash('success','El admin ha sido eliminado con éxito.');
return redirect()->route('admin.admins');
}
How can I open the modal when I open the ID of the row?