Laravel Distinct Count Laravel Distinct Count database database

Laravel Distinct Count


you can simply replace get with count in this way:

$count = DB::table('tablename')->count(DB::raw('DISTINCT name'));

also can do:

DB::table('tablename')->distinct('name')->count('name');


You may simply do the following:

Tablename::distinct()->count('name');


DB::table('tablename')->distinct()->count('name');

is the correct answer.

->distinct('name') does not work in Laravel.