jeudi 24 septembre 2015

groupBy() and then count() in Laravel

I have a table with all accesses to my mobile application.

Columns: platform(Android or iOS) and uuid (unique id)

Now I want to know how many unique user accessed with iOS. In my table are two iOS records but from the same uuid. So the correct result would be 1.

return $data['user']->application->accesses()->where('platform', 'iOS')->groupBy('uuid')->count();

This returns 2, which is wrong.

If I do:

$ios = $data['user']->application->accesses()->where('platform', 'iOS')->groupBy('uuid')->get();
return count($ios);

This returns 1, which is correct.

My is my first query returning 2 and how can I fix it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire