Laravel Group By Week

->groupBy(function($date) {
  return Carbon::parse($date->created_at)->format('W');
});

Didn’t know Carbon parse has a ‘W‘ format week!

Also, if the column is a date or datetime field you can skip Carbon::parse().

->groupBy(function($row){
    return $row->created_at->format('W');
});

Leave a Comment