How to use multiple condition in leftjoin with raw query in laravel5

Viewed 122

I need to join two table to fetch data with multiple condition on leftjoin but
i am getting this error. Not enough arguments for the on clause I am using laravel5.2. How to use raw query with leftjoin multiple condition.

    $activityDetail = DB::table('table1 as UA')
        ->selectRaw('SUM(UA.total_calory) as total_calory,
            SUM(UA.flight_descend) as flight_descend,date('.$tz_start_date.') as start_date')
        ->leftjoin('table2 as LC',function($join) use($tz_lccreated_date,$dateRange){
                $join->on('LC.user_id_fk','=','UA.user_id_fk');
                $join->on('LC.is_active','=',DB::raw('1'));
                $join->on(' date('.DB::raw($tz_lccreated_date).') '.DB::raw($dateRange));
            })
            ->whereRaw(' date('.$tz_start_date.') '.$dateRange)
            ->where('UA.user_id_fk','=',base64_decode($params['uid']))
            ->groupBy(DB::raw('date('.$tz_start_date.')'))
            ->get();

Raw query is 

select SUM(UA.total_calory) as total_calory,
SUM(UA.flight_descend) as flight_descend,
date(CONVERT_TZ(UA.start_date,"+00:00","+05:30")) as start_date 
from `table1` as `UA` 
left join `table2` as `LC` 
on `LC`.`user_id_fk` = `UA`.`user_id_fk` and `LC`.`is_active` = 1
and `date(CONVERT_TZ(LC`.`created_date,"+00:00","+05:30"))` = `current_date` 
where date(CONVERT_TZ(UA.start_date,"+00:00","+05:30")) = current_date
and `UA`.`user_id_fk` = 411 
group by date(CONVERT_TZ(UA.start_date,"+00:00","+05:30"))
1 Answers
Related