Mostly this error appear or something went wrong error showing when you are using join on #queries with join ON and multiple AND WHERE
This happens to me in #laravel 5.2 version, Following code is showing error
$SDTBL = 'SD_TBL'; $SD_TBL2 = 'SD_TBL2'; $the_second_id = 5; $SD_RECORDS = DB::table($SDTBL) ->rightJoin($SD_TBL2,function($RELTBLJOIN) use($SD_TBL2, $SDTBL,$the_second_id) { $RELTBLJOIN->on($SD_TBL2.'.sdtbl_id',$SDTBL.'id'); $RELTBLJOIN->where($SD_TBL2.'.second_where_on_id',$the_second_id); $RELTBLJOIN->where($SD_TBL2.'.status','1'); })->where($SDTBL.'.status','1')->where($SDTBL.'.e_type','2')->get();
So I figure out just add ‘=’ in 2nd parameter of $RELTBLJOIN->where method
$RELTBLJOIN->where($SD_TBL2.'.status','1'); //BEFORE $RELTBLJOIN->where($SD_TBL2.'.status','=','1'); //SOLUTION
This is complete code of fixed
$SDTBL = 'SD_TBL'; $SD_TBL2 = 'SD_TBL2'; $the_second_id = 5; $SD_RECORDS = DB::table($SDTBL) ->rightJoin($SD_TBL2,function($RELTBLJOIN) use($SD_TBL2, $SDTBL,$the_second_id) { $RELTBLJOIN->on($SD_TBL2.'.sdtbl_id','=',$SDTBL.'id'); $RELTBLJOIN->where($SD_TBL2.'.second_where_on_id','=',$the_second_id); $RELTBLJOIN->where($SD_TBL2.'.status','=','1'); })->where($SDTBL.'.status','1')->where($SDTBL.'.e_type','2')->get();