使用 Sweetalert、Javascript 和 Laravel 创建确认按钮

Create confirm button with Sweetalert, Javascript and Laravel

Html:

<form id="myform" class="delete-photo col-md-12" method="POST" action="/admin/category/{{$catget->id}}">
        <input type="hidden" name="_method" value="delete">                    
            {{ csrf_field() }}                            
            <div class="form-group">
                <button type="submit" data-photo-id="{{$catget->id}}"
                class="submitdel btn btn-danger"
                >Delete Category</button>
            </div>                    
    </form>

Js:

<script type="text/javascript">
 $('.delete-photo').click(function(e) {
   e.preventDefault(); // Prevent the href from redirecting directly
   var linkURL = $(this).attr("action");
   warnBeforeRedirect(linkURL);
 });

 function warnBeforeRedirect(linkURL) {
   swal({
     title: "Leave this site?", 
     text: "If you click 'OK', you will be redirected to " + linkURL, 
     type: "warning",
     showCancelButton: true
   }, function() {
     // Redirect the user
     window.location.href = linkURL;
   });
 }
</script>

我正在尝试使用 sweetalert 创建一个确认按钮。我试图重定向到正确的路线,这是 (http://localhost:8000/admin/category/13) 但 laravel 说:

MethodNotAllowedHttpException in RouteCollection.php line 219:....

我的路线是:

Route::delete('/admin/category/{id}', 'adminpanel@deletecategory');

可能有什么问题或解决了这个问题?

js:

 $('.delete-photo').click(function(e) {
   e.preventDefault(); // Prevent the href from redirecting directly
   var linkURL = $(this).attr("action");
   warnBeforeRedirect(linkURL);
 });

 function warnBeforeRedirect(linkURL) {
   swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        cancelButtonText: "No, cancel plx!",
        closeOnConfirm: false,
        closeOnCancel: false 
    },
    function(isConfirm) {
        if (isConfirm) {                        
            document.getElementById("myform").submit(); 
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    }
);
 }

我的问题是: 1)提交必须通过表单激活控制器方法删除。 2) previus javascript 没有拿csrf token