This simple laravel group by week tutorial demonstrates of laravel group by week example. In this laravel groupby tutorial i wanna show you laravel group by week example. We will use laravel eloquent group by week. So if you don't know how to fetch data week wise then this example is for you.
I have used created_at column with timestamp and we wanted to get laravel group by day of week. However, from this tutorial you will learn how to get laravel eloquent group by week wise data. So let's see the example of laravel eloquent group by week.
Example of laravel eloquent group by week:
$inspections = VehicleInspection::select('*')
->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('W');
});
Read also: Laravel Eloquent Group By Month and Year with Sum Example
Hope it can help you.
#laravel #laravel-8x #eloquent-tips