I am trying to delete a record with double confirmation of sweet alert from a datatables, but when selecting one, it always sends me the id 1, no matter what the record is with the id 10, 20 or 30. What should be done? or what am I doing wrong ?. Annex code that generates the list
@foreach ($array as $row)
<tr>
<td>
<img src="{{ asset('uploads/users/'.$row->login.'/image.png') }}" style="max-width:30px;">
{{ $row->firstName.' '.$row->lastName }}
</td>
<td>
{{ $row->email }}
</td>
<td>
{{ $row->login }}
</td>
<td>
<!-- Action buttons -->
<div>
{!! Form::open(array('route' => array($options['route'].'.destroy', $row->id), 'method' => 'DELETE', 'id' => 'myform'.$row->id)) !!}
<a href="{{ route($options['route'].'.show', $row->id) }}" class="btn btn-warning btn-sm">
<i class="la la-small la-edit"></i>
</a>
<button type="button" id="delete" data-id="<?php echo $row->id; ?>" class="btn btn-danger btn-sm"><i class="la la-small la-trash"></i></button>
{!! Form::close() !!}
</div>
</td>
</tr>
@endforeach
and the js function that the Sweet alert generates
$('button#delete').on('click', function() {
var id = $(this).attr('data-id');
swal({
title: "¿Desea eliminar el usuario?",
text: "",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Si!!",
cancelButtonText: "No!!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
swal({
title:'¡El usuario será eliminado!',
text: '',
type: 'success'
},
function() {
$("#myform"+id).submit();
});
} else {
swal("Cancelled", "El usuario no será eliminado!!", "error");
}
});
})