I have below query code but i am not getting correct result. Is there any logical mistake in my code?
$tasks = Task::where('deleted_at', null);
$tasks = $tasks->where(function($q) use ($user_id,$company_id, $task_ids){
$q->where(function($q2) use ($user_id,$company_id, $task_ids) {
$q2->where('created_by',$user_id)
->where('company_id',$company_id);
})
->orWhereIn('id',$task_ids);
});
$tasks_today = $tasks;
$tasks_tomorrow = $tasks;
$tasks_week = $tasks;
$tomorrow = date("Y-m-d", strtotime("+1 day"));
$today_cnt = $tasks_today->whereDate('due_date','=',date('Y-m-d H:i:s'))->count();
$tomorrow_cnt = $tasks_tomorrow->whereDate('due_date','=',$tomorrow)->count();
$week_count = $tasks_week->whereBetween('due_date', [Carbon::now()->startOfWeek(),
Carbon::now()->endOfWeek()])->count();
$due_result[] = array(
'due_today' => $today_cnt,
'due_tomorrow' => $tomorrow_cnt,
'due_this_week'=>$week_count,
'due_all'=>$tasks->count()
);