tomasosho's avatar

how to count entries per month

how do i count entries monthly 1st to last day of every month? i'm making use of datatable package from which month and year can be selected. i'd love an example. Thank you!

0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Something like this?

foreach (range(1,12) as $i) {
    $month = Carbon::create()->day(1)->month($i);
    $counts[$i] = Model::whereBetween('date', $month, $month->copy()->endOfMonth())->count();
}
1 like

Please or to participate in this conversation.