简体   繁体   中英

delete multiple records in laravel using form submit

Hi I need to delete multiple user records, selected by multiple check boxes and then press delete and submit the form userListform .

  1. In the view I have added anchor with javascript deleteUser()
<a href="javascript:void();" class="btn btn-outline-danger" onclick="deleteUser();">Delete</a>
  1. in the view
<form method="POST" action="{{url('/user/delete')}}" id="userListform" >
  1. in the route
Route::post('/user/delete', 'UsersController@delete');
  1. Delete function

function deleteUser(){    
    var $checkboxes = jQuery('#userListform input[type="checkbox"]');
    checkedItems = $checkboxes.filter(':checked').length;    
    if(checkedItems > 0){
        var status = confirm("Do you need to delete the user!!");   
        if (status == true) {                        
            document.getElementById("userListform").submit(); 
        } else {
            return false;
        }
    }else{
        alert("Please select the users to be deleted!");    
    }
}

I have successfully submited the form but i'm not getting to the delete function of the usercontroller@delete method , instead it is showing 404 error

在表单中添加csrf令牌,它将起作用

You can try this

in the view
<form method="POST" action="{{route('user.delete')}}" id="userListform" >

in the route
Route::post('/user/delete', 'UsersController@delete')->name('user.delete);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM