Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dinojames2's avatar

How to get monthly wise data in laravel

I have a lot of data. I want to bring the data from the database as a monthly wise. I have already used group by method but when I want to view the data all the data is showing but I want to see the specific month data. Below are my codes. Please help me.

    public function RentCertificate(){
        $data['fiscal_year'] = FiscalYear::all();
        $data['month'] = Month::all();
        $data['report'] = Report::status(1)->desk(15)->distric()->rentcertificate()->groupBy('month')->get();
        $data['upazila'] = Upazila::all();
        $data['upazilaoffice'] = UpazilaOffice::all();
        $data['user'] = User::all();
        $data['districoffice'] = DistricOffice::all();
        return view('adcr.report.rent_certificate', $data);
    }

This is my view code

  @foreach($report as $full_info)
<tr>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_one}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_two}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_three}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_four}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_five}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_six}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_seven}}</td>
<td style="text-align: center; border: 1px solid #000000; width: 2%" class="">{{$full_info->column_eight}}</td>
</tr>
@endforeach

My Database like

|column_one|column_two|column_three|column_four|column_five|month|
|1						|2						  | 3						 | 4						| 4					| January|
|4					|3						  | 42						 | 41						| 44					| January|
|2						|23					|	4						|	2						| 4					| February|
0 likes
3 replies
sr57's avatar

@dinojames2

Good to give a sample of your date but it's difficult to understand your code.

You should have 3 parts, the controller, the view and the route that links both.

jlrdw's avatar

$data['fiscal_year'] = FiscalYear::all();

You need to use some between dates for one month. And what report? Summaries or detail? There's a big difference.

1 like
MohammedSB's avatar

You can use the following

  • For today data Model::whereDate('created_at', Carbon::today())->get()

  • For weekly data Model::whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get()

  • For yearly data Model::whereBetween('created_at', [Carbon::now()->startOfYear(), Carbon::now()->endOfYear()])->get()

  • For specific date range Model::whereBetween('created_at', [FROM DATE, TO DATE])->get()

  • For specific day Model::whereDate('created_at', DATE OF DAY)->get()

1 like

Please or to participate in this conversation.