Not enough arguments for the on clause laravel

0.28K views
no comments
4 Jan 2017 1:07 am

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

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>