mardi 5 mars 2019

How to Delete After Confirmation by Sweet-alert in Laravel...?

I have linked sweetalert plugin for my confirmation message. But it's not getting the confirmation command (onclick yes/confirm button).

This is my delete button:

<a id="demoSwal" href="" class="btn btn-light btn-sm btn-delete demoSwal" data-toggle="tooltip" data-placement="top" title="Delete This Type"><i class="far fa-trash-alt"></i></a>

This is My JS Code:

$(document).ready(function(){
    $('.demoSwal').click(function(){
            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this file!",
                type: "warning",
                showCancelButton: true,
                confirmButtonText: "Yes, delete it!",
                cancelButtonText: "No, cancel plx!",
                closeOnConfirm: false,
                closeOnCancel: false
            },
            function(isConfirm) {
                if (isConfirm) {
                    swal("Deleted!", "Your Data file has been deleted.", "success");
                } else {
                    swal("Cancelled", "Your Data file is safe :)", "error");
                }
            });
        });
});

This is my Controller Code:

public function destroy($id)
    {
        $delete_website_type = WebsiteType::find($id);
        $delete_website_type->delete();

        return redirect()->back();

    }

Please Give me the solution...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire