Laravel Eloquent - distinct() and count() not working properly together

前端 未结 12 1108
甜味超标
甜味超标 2020-12-04 15:54

So I\'m trying to get the number of distinct pids on a query, but the returned value is wrong.

This is what I try to do:

$ad->getcodes()->group         


        
12条回答
  •  春和景丽
    2020-12-04 16:57

    A more generic answer that would have saved me time, and hopefully others:

    Does not work (returns count of all rows):

    DB::table('users')
                ->select('first_name')
                ->distinct()
                ->count();
    

    The fix:

    DB::table('users')
                ->distinct()
                ->count('first_name');
    

提交回复
热议问题