Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 单击多个复选框时删除记录_Php_Jquery_Ajax_Laravel - Fatal编程技术网

Php 单击多个复选框时删除记录

Php 单击多个复选框时删除记录,php,jquery,ajax,laravel,Php,Jquery,Ajax,Laravel,我想删除复选框中选中的一条记录,并同时删除整个记录 这是用户可以选择“全选”复选框的选项卡 <button type="checkbox" id="checkall" class="btn btn-default btn-sm checkbox-toggle"> <i class="fa fa-square-o" ></i> </button> <div class="btn-group"> <button typ

我想删除复选框中选中的一条记录,并同时删除整个记录

这是用户可以选择“全选”复选框的选项卡

<button type="checkbox" id="checkall" class="btn btn-default btn-sm checkbox-toggle">
    <i class="fa fa-square-o" ></i>
</button>
<div class="btn-group">
    <button type="submit" class="btn btn-default btn-sm" >
        <i class="fa fa-trash-o"></i>
    </button>
</div>

<!-- /.btn-group -->
<a href="{{ route('home.notificationbox') }}">
    <button type="button" class="btn btn-default btn-sm">
        <i class="fa fa-refresh"></i>
    </button>
</a>
控制器,这已被删除

public function delete_admin_notification(Request $request)
{
    if(!empty($request)) {

        $adminNotification=AdminNotification::find($request['notification_id'])->delete();
        return redirect()->back();
    } else {
        return false;
    }   
}
public function deleteMultipleMail(Request $request)
{
    dd($request);
    $delId = $request->input('deleteMultipleMail');
    AdminNotification::whereIn('notification_id' , $delId)->delete();
    return redirect()->back();
}
路由页面

Route::post('/deleteMultipleMail','HomeController@deleteMultipleMail');
单击复选框删除所有记录,或仅选择要删除的记录。

在js文件中:

$('.delete-all').on('click', function(e) {
    var idsArr = []; 

    $('.checkbox').each(function(){
        var isChecked = $(this).prop('checked');

        if(isChecked){
            idsArr.push($(this).val());
        }
    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        url: "/deleteMultipleMail",
        type: 'POST',
        data:{
            idsArr: idsArr
        },
        success: function (response) {
            if(response.success){
             window.location = response.redirect_url; 
            } else {
                alert('Whoops Something went wrong!!');
            }
        },
        error: function (data) {
            alert(data.responseText);
        }
    });
});
在控制器中:

public function deleteMultipleMail(Request $request)
{
    $post = $request->all();

    AdminNotification::whereIn('notification_id' , $post['idsArr'])->delete();

    return response()->json(['success' => true, 'redirect_url' => 'your redirect url']);
}

它会在电子邮件的第一行转储并死亡吗?或者你不使用该函数吗?我只是在“->delete()的帮助下更新了一个delete_at column,它只是更新了一个delete_at column对不起,我不明白你在说什么单击一个复选框,我没有获取存储到var idsArr=[]的id;var strIds=idsArr.join(“,”);是的,这就是问题所在,但我的问题是,他是否在电子邮件的第一行执行dd()操作?这是一个肯定/否定的问题
$('.delete-all').on('click', function(e) {
    var idsArr = []; 

    $('.checkbox').each(function(){
        var isChecked = $(this).prop('checked');

        if(isChecked){
            idsArr.push($(this).val());
        }
    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        url: "/deleteMultipleMail",
        type: 'POST',
        data:{
            idsArr: idsArr
        },
        success: function (response) {
            if(response.success){
             window.location = response.redirect_url; 
            } else {
                alert('Whoops Something went wrong!!');
            }
        },
        error: function (data) {
            alert(data.responseText);
        }
    });
});
public function deleteMultipleMail(Request $request)
{
    $post = $request->all();

    AdminNotification::whereIn('notification_id' , $post['idsArr'])->delete();

    return response()->json(['success' => true, 'redirect_url' => 'your redirect url']);
}