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
You are Performing action on button click irrespective of whether you confirm or cancelled the deletion.
Delete
Jquery and Ajax:
$(document).on('click', '.button', function (e) {
e.preventDefault();
var id = $(this).data('id');
swal({
title: "Are you sure!",
type: "error",
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes!",
showCancelButton: true,
},
function() {
$.ajax({
type: "POST",
url: "{{url('/destroy')}}",
data: {id:id},
success: function (data) {
//
}
});
});
});
And:
public function destroy(Request $request)
{
User::find($request->id)->delete();
return redirect()->route('users.index')
->with('success','User deleted successfully');
}