'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.

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>{{$full_info->column_one}}</td>
    <td>{{$full_info->column_two}}</td>
    <td>{{$full_info->column_three}}</td>
    <td>{{$full_info->column_four}}</td>
    <td>{{$full_info->column_five}}</td>
    <td>{{$full_info->column_six}}</td>
    <td>{{$full_info->column_seven}}</td>
    <td>{{$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|


Solution 1:[1]

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

check ->where('month','January')->get(); you can make your function dynamic by passing the month value into it.

public function RentCertificate($month){
$data['fiscal_year'] = FiscalYear::all();
$data['month'] = Month::all();
$data['report'] = Report::status(1)->desk(15)->distric()->rentcertificate()->groupBy('month')->where('month',$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);
}

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 S_B