I am trying to implement sweet alert on my laravel project. But the delete method is working without the sweetalert.
in my blade file--
<div class="action-btn bg-danger ms-2">
<a class="delete-confirm" href="{{ URL::to('/delete-customer/' . $customer->id) }}" type="button">
<i class="ti ti-trash delete-confirm"></i></a>
</div>
in my controller--
public function delete($id)
{
$customer = Customer::findOrfail($id);
$customer->delete();
return redirect()->back()->with('success', __('Customer successfully deleted.'));
}
For sweetalert I used this code--
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
$('.delete-confirm').on('click', function (event) {
event.preventDefault();
const url = $(this).attr('href');
swal({
title: 'Are you sure?',
text: 'This record and it`s details will be permanantly deleted!',
icon: 'warning',
buttons: ["Cancel", "Yes!"],
}).then(function(value) {
if (value) {
window.location.href = url;
}
});
});
</script>
when I click delete button it doesn't show the sweet alert. Can anyone explain what did I miss?