In this article, we will get to know how to get month wise data in laravel. We will use laravel eloquent to month wise data.
There are many ways to get month wise data in laravel, but I will show you the easiest way with the example so that you can understand how we can get month wise data.
Let’s suppose I have a controller named as employee controller, where I have to get the employee data who are joined in a particular month.
$request->month = date('Y-m', strtotime($request->month)); // here request month = getting data from form $employee = Employee::where('created_at', 'LIKE', "%$request->month%")->get();
In the $request->month I am getting the data in this way 2021-04-08, but our target is to get the data month wise that’s why I remove the date.
If you run the above code you will get the data of employees created in the particular month.
I hope you understood the basic concept of how to get data month wise in laravel.