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.
You could use this:
$reserves = DB::table('reserves')->selectRaw('*, count(*)')->groupBy('day');
Hope it helps!!
$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)
This can be done with the ...READ MORE
Inside controller inject Request object. So ...READ MORE
The code below solved my problem:
$messages ...READ MORE
Laravel intercepts all input. If you're ...READ MORE
When the variable is passed as value ...READ MORE
You have to provide MySQL hostname, ...READ MORE
Actually there are many functions that ...READ MORE
mysqli_pconnect() function is used for making a persistence ...READ MORE
We need to create a new model ...READ MORE
Go to the phpMyAdmin website, download the latest ...READ MORE
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.