Confirmation before deleting record

1

I have a link that when clicking opens a modal asking if the user wants to delete the record. In the link I have a href that calls a route to do the deletion. How could you do to call this route only if you click the delete button?

Link:

<a id="danger-alert" href="{{ route('admin.categories.destroy', $category) }}"><i class="zmdi zmdi-delete zmdi-hc-lg"></i></a>

Function:

$('#danger-alert').click(function () {
    swal({
        title: "Deseja excluir o registro?",
        //text: "You will not be able to recover this imaginary file!",
        type: "error",
        showCancelButton: true,
        confirmButtonClass: 'btn-danger waves-effect waves-light',
        confirmButtonText: 'Excluir'
    });
});
    
asked by anonymous 08.11.2017 / 13:49

1 answer

0

I was able to find the solution. In case lib is SweetAlert for Bootstrap

<a id="danger-alert" data-link="{{ route('admin.categories.destroy', $category) }}"><i class="zmdi zmdi-delete zmdi-hc-lg"></i></a>

$('#danger-alert').click(function () {
    swal({
          title: "Tem certeza?",
          type: "error",
          showCancelButton: true,
          confirmButtonClass: "btn-danger",
          confirmButtonText: "Excluir",
          closeOnConfirm: false
    },
    function(){
       window.location.href = $('#danger-alert').attr("data-link");
    });
});
    
08.11.2017 / 14:30