I m counting records on the base of user id but giving different results. running two query on is single send in foreach but counting result is different. when i m counting each records of second it gives 3705 and first single query with whereIn it gives me 3692. how can i find the issue.
$users = [248, 255, 260, 299, 300, 301, 259];
$tlw_count = [];
// Single querry Count giving 3692
$tlw = \App\Models\Lead::whereHas('LeadTasks', function ($query) use ($users) {
$query->where('internal_inquiry_status_id', '!=', 3)
->whereIn('created_by', $users);
})->count();
// Foreach loop for individual count giving 3705
foreach ($users as $value) {
$tlw_counted = \App\Models\Lead::whereHas('LeadTasks', function ($query) use ($value) {
$query->where('internal_inquiry_status_id', '!=', 3)
->where('created_by', $value);
})->count();
$tlw_count[$value] = $tlw_counted;
}
dd($tlw_count, $tlw);