2017-09-28 90 views
0

我想從我的控制器上運行laravel的聯接查詢,但我得到了「調用成員函數leftJoin()null」將查詢結果加入到「調用成員函數leftJoin()null」

public function tracking_groupindividual(Request $request) 
{ 
    $user_id = $request->user_id; 
    $group_id = $request->group_id; 

    $get_group_individual_details = DB::table('group_usermapping as gu') 
     ->select(
      'um.user_id', 
      'um.user_name', 
      'um.image_path', 
      'um.mobile_number', 
      'ul.latitude', 
      'ul.longitude', 
      'um.isnearby_on', 
      'gu.isadmin', 
      'um.profile_status', 
      'ul.timedout' 
     ) 
     ->join('user_master as um','gu.user_id','=','um.user_id') 
     ->join('groupusers_location as ul','ul.user_id','=','um.user_id','ul.group_id','=','gu.group_id') 
     ->where(function ($query) use ($group_id) { 
      $query->where('gu.group_id', '=', $group_id) 
       ->where('gu.isactive','=','1')->where('um.isactive','=','1'); 
     })->get(); 

     return $get_group_individual_details; 
    } 

回答

0

我在第二個連接中發現的問題和固定它

public function tracking_groupindividual(Request $request) 
{ 
    $user_id = $request->user_id; 
    $group_id = $request->group_id; 

    $get_group_individual_details = DB::table('group_usermapping as gu') 
     ->select(
      'um.user_id', 
      'um.user_name', 
      'um.image_path', 
      'um.mobile_number', 
      'ul.latitude', 
      'ul.longitude', 
      'um.isnearby_on', 
      'gu.isadmin', 
      'um.profile_status', 
      'ul.timedout' 
     ) 
     ->join('user_master as um','gu.user_id','=','um.user_id') 
     ->join('groupusers_location as ul', function ($join) { 
      $join->on('ul.user_id','=','um.user_id') 
       ->where('ul.group_id','=','gu.group_id'); 
     }) 
     ->where(function ($query) use ($group_id) { 
      $query->where('gu.group_id', '=', $group_id) 
       ->where('gu.isactive','=','1')->where('um.isactive','=','1'); 
     })->get(); 

     return $get_group_individual_details; 
    } 
+0

現在在選擇「調用成員函數select()null」時出現相同的錯誤「@Morteza Rajabi – Akumar

+0

使用Use Illuminate \ Support \ Facades \ DB在我的控制器中導入數據庫類 – Akumar

0

嘗試使用DB ::生()的別名!

$get_group_individual_details = DB::table(DB::raw('group_usermapping as gu')) 
           ->join(DB::raw('user_master as um'),DB::raw('gu.user_id'),'=',DB::raw('um.user_id')) 
           ->join(DB::raw('groupusers_location as ul'),DB::raw('ul.user_id'),'=',DB::raw('um.user_id'),DB::raw('ul.group_id'),'=',DB::raw('gu.group_id')) 
           ->select(DB::raw('um.user_id'),DB::raw('um.user_name'),DB::raw('um.image_path'),DB::raw('um.mobile_number'),DB::raw('ul.latitude'),DB::raw('ul.longitude'),DB::raw('um.isnearby_on'),DB::raw('gu.isadmin'),DB::raw('um.profile_status'),DB::raw('ul.timedout')) 
           ->where(function ($query) use ($group_id) { 
             $query->where(DB::raw('gu.group_id'), '=', $group_id)->where(DB::raw('gu.isactive'),'=','1')->where(DB::raw('um.isactive'),'=','1'); 
             })->get(); 

return $get_group_individual_details; 

和替換使用照亮的\ Support \外立面\ DB;使用DB;

相關問題