mardi 8 septembre 2020

Laravel query builder does not work as expected using orWhere conditions

I want to convert the sql query to laravel

my sql query is working fine and show only active_state=1 record but laravel query qhows inactive rows also.what I did wrong

select a.id,a.assigned_user_name,a.meeting_start_date,a.call_start_date
from mgl_report_targets as a 
  left join dcalendardate b on b.datevalue=a.meeting_start_date 
  left join dcalendardate c on c.datevalue=a.call_start_date  
where (b.datevalue > '2020-07-31' and b.datevalue < '2020-09-01')
  or ( c.datevalue > '2020-07-31' and c.datevalue < '2020-09-01') 
  and a.active_status='1'

I have tried

$report_details=DB::table('mgl_report_targets');
$report_details=$report_details->leftjoin('dcalendardate as a','a.datevalue','=',DB::raw("mgl_report_targets.meeting_start_date::date")); 
$report_details=$report_details->leftjoin('dcalendardate as b','b.datevalue','=',DB::raw("mgl_report_targets.call_start_date::date"));
$report_details=$report_details->where('a.datevalue','>','2020-07-31');
$report_details=$report_details->where('a.datevalue','<','2020-09-01');
$report_details=$report_details->orWhere('b.datevalue','>','2020-07-31');
$report_details=$report_details->orWhere('b.datevalue','<','2020-09-01');
$report_details=$report_details->where('mgl_report_targets.active_status','=','1');
$report_details=$report_details->select('mgl_report_targets.id','mgl_report_targets.assigned_user_name','mgl_report_targets.meeting_start_date','mgl_report_targets.call_start_date')
->get();


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire