0

I'm trying to loop over and query two values, and get the count. Laravel only returns one result in the array. I feel like its doing the whereBetween once, and no further. Does this look right?

$queryTotals = $users->query();

foreach($times as $k => $v) 
{
    $time_group[$k]['count'] = $queryTotals->whereBetween('join_date', array($v[0], $v[1]))
                                           ->get()
                                           ->count();
}

It's comparing between two values (two timestamps), and counting the total of members between that range.

0

1 Answer 1

1

Your problem seems to be reusing the query, you are adding whereBetween to it by using the loop. To reuse the same query again and again just copy your old query into a new variable, I think that should do the trick. I haven't tried the code since I have no idea about your previous variables.

$queryTotals = $users->query();

foreach($times as $k => $v) 
{
    $nq = $queryTotals;
    $time_group[$k]['count'] = $nq->whereBetween('join_date', array($v[0], $v[1]))
                                           ->get()
                                           ->count();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.