I have a button
that calls a modal to confirm deletion, this is in a table, each line a button
to exclude the registration of that line
But the way it is, it always deletes the first item from the list
<button type="button" id="btn-modal" cidadao-id="{{$cidadao->id}}" class="btn-modal" data-toggle="modal" data-target="#modal-default">{{$cidadao->id}}</button>
<div class="modal fade" id="modal-default">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">Confirmação</h4>
</div>
<div class="modal-body">
<p>Deseja realmente excluir o cadastro?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Fechar</button>
<form id="formdelete" class="form-vertical" method="POST" action="{{ action('CidadaoController@destroy', $cidadao->id)}}">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-primary">{{$cidadao->id}}</button>
</form>
</div>
</div>
</div>
</div>
I was able to capture the correct id with JS:
$('.btn-modal').click(function(){
var id = $(this).attr('cidadao-id');
console.log(id);
//document.formdelete.action = "{{ action('CidadaoController@destroy', id)}}";
})
I tried to replace the action to use the id that I captured, but it did not work
How could I delete the captured id's record?