'How to show monthly wise data in Laravel
I am working on a report management system. The function of this application is that some users will enter their office information every month and the admin will be able to see them. Now I want to show the user entered information monthly wise. Suppose the user generates data for the month of January and when the admin clicks in January he will see all the information for the month of January. I'm new so I don't know how to do it.
I have used this method but when I use it all the monthly data is coming but I want to bring the specific month data.
public function RentCertificate(){
$report = Report::distric()->status(1)->desk(15)->groupBy('month', 'fiscal_year')->get();
return view('adcr.report.rent_certificate', compact('report'));
}
This is exactly what my database looks like.
| column_one | month | fiscal_year | user_id |
|---|---|---|---|
| 1381238 | January | 2021-2022 | 1 |
| 4131813 | January | 2021-2022 | 2 |
| 5381313 | February | 2021-2022 | 3 |
| 8173123 | February | 2021-2022 | 2 |
Solution 1:[1]
you can use the code below to filter by month.
Just change the $date variable.
$date = "2022-05-17 22:55:07";
$month = Carbon::parse($date)->format('m');
return Report::whereMonth('created_at', '=', $month)->get();
OR
return Report::whereMonth('created_at', '=', "01")->get(); // for January
return Report::whereMonth('created_at', '=', "02")->get(); // for February
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
