Ad

How Do I Get A "select Count(*) Group By" Using Laravel Eloquent

- 1 answer

I would like to execute the follow sentence using laravel eloquent

SELECT *, count(*) FROM reserves  group by day

The only solution occurs to me is to create a view in the DB, but I am pretty sure there is a way to do it in laravel way.

Ad

Answer

You could use this:

$reserves = DB::table('reserves')->selectRaw('*, count(*)')->groupBy('day');
Ad
source: stackoverflow.com
Ad