89774/how-do-i-get-a-select-count-group-by-using-laravel-eloquent
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.
Hello @kartik,
You could use this:
$reserves = DB::table('reserves')->selectRaw('*, count(*)')->groupBy('day');
Hope it helps!!
Thank you!!
More like:
$reserves = DB::table('reserves')->select(DB::raw('*, count(*)'))->groupBy('day')->get();
if addidtional param with count is needed, or if just count is needed:
$count = Reserve::groupBy('day')->count();
all explained in documentation (https://laravel.com/docs/8.x/queries#raw-expressions and https://laravel.com/docs/8.x/eloquent#retrieving-aggregates)
Hello @kartik, This can be done with the ...READ MORE
Hello @kartik, Inside controller inject Request object. So ...READ MORE
Hello @kartik, The code below solved my problem: $messages ...READ MORE
Hii @kartik, Laravel intercepts all input. If you're ...READ MORE
Hello, When the variable is passed as value ...READ MORE
Hey @kartik, You have to provide MySQL hostname, ...READ MORE
Hello kartik, Actually there are many functions that ...READ MORE
Hello, mysqli_pconnect() function is used for making a persistence ...READ MORE
We need to create a new model ...READ MORE
Hello, Step 1: Go to the phpMyAdmin website, download the latest ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.