删除多行 Laravel

Delete Multime Row Laravel

在那里我有一个数据,我想在我 selected 的地方添加一个删除数据。 这是我的代码:

public function postDeleteall(){
        $id = Request::get('id');
        if($id ==''){
            Session::flash('delete', 'select first !');
            return redirect()->back();
        }else{
            foreach ($id as $q) {
                $qwery = DB::table('log_patrols')->where('id',$q)->get();
                foreach ($qwery as $a) {
                    DB::table('log_patrols')->where('id',$a->id)->delete();
                    $row =DB::table('log_patrol_details')->where('id_log_patrols',$a->id)->get();
                    foreach ($row as $qwe) {
                        @unlink(public_path("uploads/".$qwe->photo1));
                        @unlink(public_path("uploads/".$qwe->photo2));
                        @unlink(public_path("uploads/".$qwe->photo3));
                    }

                    $rows = DB::table('log_patrol_details')->where('id_log_patrols',$q)->delete();
                    Session::flash('delete', 'success');
                    return redirect()->back();
                }

            }
        }
    }

当我尝试打印数据时 $id

它想获取我 select 所在的数据 ID,但在我尝试编写代码后,它不会像我想要的那样工作。并且它只删除我 selected 的 1 个数据。 我应该怎么办 ?我的脚本需要更改哪些代码?

谢谢

您在删除第一个巡逻后正在重定向。移动

Session::flash('delete', 'success');
return redirect()->back();

在您的 foreach ($id as $q) 循环之外。

public function postDeleteall()
        {
            $id = Request::get('id');
            if ($id == '') {
                Session::flash('delete', 'select first !');
                return redirect()->back();
            } else {
                foreach ($id as $q) {
                    $qwery = DB::table('log_patrols')->where('id', $q)->get();
                    foreach ($qwery as $a) {
                        DB::table('log_patrols')->where('id', $a->id)->delete();
                        $row = DB::table('log_patrol_details')->where('id_log_patrols', $a->id)->get();
                        foreach ($row as $qwe) {
                            @unlink(public_path("uploads/" . $qwe->photo1));
                            @unlink(public_path("uploads/" . $qwe->photo2));
                            @unlink(public_path("uploads/" . $qwe->photo3));
                        }

                        $rows = DB::table('log_patrol_details')->where('id_log_patrols', $q)->delete();
                    }

                }
                Session::flash('delete', 'success');
                return redirect()->back();
            }
        }