Laravel Group By Week Query Example

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.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js