I\'m testing a method using Sweet Alert, to improve the messages issued by the Javascript alert method with the laravel framework.
1 - I downloaded the files sweetal
I have implemented this code in my laravel project and delete data by using route name with slug. This code is working for me. And i also delete row from table without reload() by using with id. So try this code let me know it's working for you or not.
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
function confirmDelete(slug) {
swal({
title: "Are you sure!",
type: "error",
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes!",
showCancelButton: true,
})
.then((willDelete) => {
if (willDelete.value == true) {
var url = '{{ route("instrument.delete", ":slug") }}';
url = url.replace(':slug', slug);
$.ajax({
url: url,
type: "POST",
data: {
'_method': 'DELETE'
},
success: function (data) {
if (data.status == 1) {
swal({
title: "Success!",
type: "success",
text: "Instrument has been deleted \n Click OK",
icon: "success",
confirmButtonClass: "btn btn-outline-info",
});
$('#tr' + data.slug).remove();
}
},
error: function (data) {
swal({
title: 'Opps...',
text: data.message,
type: 'error',
timer: '1500'
})
}
})
}
});
}