2017-01-11 63 views
0

在那裏我有一個數據,我想添加一個刪除數據在我選擇的地方。 這裏我的代碼:刪除Multime行Laravel

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

here

其想要得到的數據id其中我選擇,但之後我儘量讓它的代碼不會像我想要的那樣工作。其唯一的刪除1我選擇的數據。 我該怎麼辦?以及我需要更換哪些代碼?

謝謝

回答

0
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(); 
      } 
     } 
0

您在刪除第一個巡視後重定向。移動

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

以外的foreach ($id as $q)循環。