Laravel 带有甜蜜提醒的删除功能

Laravel delete function with Sweet Alert

所以我在 laravel 5.7.

上使用 sweet alert

我需要帮助,因为我点击甜蜜提醒确认按钮后,该功能似乎不起作用。

我的html:

<button rel="{{ $mail->id }}"" rel1="delete-mail" href="javascript:" 
class="deleteMail btn btn-danger btn-xs">Delete</button></td>

我的脚本:

    $(".deleteMail").click(function(){
    var id = $(this).attr('rel');
    var deleteFunction = $(this).attr('rel1');
    swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        confirmButtonText: 'Yes, delete it!',
        buttonsStyling: false

    },
    function(){
      window.location.href='/admin/'+deleteFunction+'/'+id;
    });

    });

路线:

public function delete($id = null){

    if(!empty($id)){
        Mail::where(['id'=>$id])->delete();
        return redirect()->back()->with('flash_message_success','Surat berhasil dihapus!!');
    }

}

我试过window.location.href没有甜蜜提醒功能,效果很好。

但是,当我使用 sweet alert 时,它根本不起作用。

我在 console log 中找不到任何错误。请帮助。

尝试 .then 功能。 例如:

  $(".deleteMail").click(function(){
  var id = $(this).attr('rel');
  var deleteFunction = $(this).attr('rel1');
  swal({
      title: 'Are you sure?',
      text: "You won't be able to revert this!",
      type: 'warning',
      showCancelButton: true,
      confirmButtonClass: 'btn btn-success',
      cancelButtonClass: 'btn btn-danger',
      confirmButtonText: 'Yes, delete it!',
      buttonsStyling: false

    }).then((isConfirm) => {


   if (isConfirm){
       window.location.href='/admin/'+deleteFunction+'/'+id;
     }
    });
    });

尝试

 $(".deleteMail").click(function(){
    var id = $(this).attr('rel');
    var deleteFunction = $(this).attr('rel1');
    swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        confirmButtonText: 'Yes, delete it!',
        buttonsStyling: false

    },function(isConfirm){
        alert('ok');
    });
    $('.swal2-confirm').click(function(){
        window.location.href='/admin/'+deleteFunction+'/'+id;
    });
});