Level 73
@phpmick what about this:
$page->events
->whereBetween('created_at', [$this->from, $this->to])
->selectRaw('date(created_at) as date, count(*) as total')
->groupBy('date')
->get();
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I am trying to group by the created_at date and get a count of the records(events) for each day.
I currently have this but it's not quite there:
$page->events
->whereBetween('created_at', [$this->from, $this->to])
->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('Y-m-d'); // grouping by years
});
Cheers,
Mick
@phpmick what about this:
$page->events
->whereBetween('created_at', [$this->from, $this->to])
->selectRaw('date(created_at) as date, count(*) as total')
->groupBy('date')
->get();
Please or to participate in this conversation.