Answer the question
In order to leave comments, you need to log in
Bulk Ajax deletion of Laravel 5.3 records?
My ajax request:
var users_ids = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
$.ajax({
url: '/users/mass_delete',
type: 'DELETE',
data: {
"users_ids": users_ids,
"_method": 'DELETE',
"_token": token,
},
})
.done(function( response ) {
console.log("Success!!!");
})
.fail(function() {
console.log("Error!!!");
})
Route::delete('users/mass_delete', '[email protected]_delete');
public function mass_delete( Request $users_ids ){
$ids = $users_ids->all();
$ids_to_delete = array_map(function($item){ return $item[0]; }, $ids);
DB::table('users')->whereIn('user_id', $ids_to_delete)->delete();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question