Level 34
Oct 30, 2023
1
Level 2
Select average daily number of rows with Laravel
Hello there,
I want to select the average daily number of rows based on created_at column. I want to achieve that with Laravel query scopes. Any suggestions?
protected function scopeDaily(Builder $query): void
{
$query
->selectRaw('DATE(created_at) as date, COUNT(*) as daily_count')
->groupBy('date');
}
protected function scopeDailyAverage(Builder $query): void
{
// here I want to apply the average method
}
Here is what I have so far.
Thank you
Please or to participate in this conversation.