Answer the question
In order to leave comments, you need to log in
Group identical records and return their count Laravel 5.3?
There are thousands of different records in the table, and it is growing. The structure is something like this:
Now we need to group all columns where the voted_for is the same, returning their number and the string in the voted_for column.
Approximately such a grouping result, 11 is the number of identical Half-Life keys: ['votes' => '11', 'for' => 'Half-Life'].
Answer the question
In order to leave comments, you need to log in
$allVotes = DB::table('votes')
->select('voted_for', DB::raw('count(*) as total'))
->groupBy('voted_for')
->get();
dd($allVotes);
SELECT COUNT(voted_for), voted_for FROM table GROUP BY voted_for;
$v = App\Model::where('voted_for', 'Half-Life')->get();
$v->count();
See secret link for more information.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question