'Monthly wise data show issues in Laravel 8
I want to show the data in my database on a monthly basis. Since I have two data for the month of May in my database, now I want to see all the data for the month of May as soon as I click in May, so I used this query:
public function RentCertificate(){
$report = Report::select('reports.*',DB::raw("MONTHNAME(created_at) as monthname"))
->whereYear('created_at', date('Y'))
->groupBy('monthname')
->get();
return view('adcr.report.rent_certificate', compact('report'));
}
And I used this query to show specific month data:
public function ViewRentCertificate($id)
{
$report = Report::where('month', $id)->get()->groupBy('month');
dd($report);
}
But when I write this query, my data comes of an array. This is the output:
Illuminate\Database\Eloquent\Collection {#1424 ▼
#items: array:1 [▼
"May" => Illuminate\Database\Eloquent\Collection {#1417 ▼
#items: array:2 [▼
0 => App\Models\Basic\Report {#1433 ▶}
1 => App\Models\Basic\Report {#1434 ▶}
]
#escapeWhenCastingToString: false
}
]
#escapeWhenCastingToString: false
}
When I used this query to show data in my view:
public function ViewRentCertificate($id)
{
$report = Report::where('month', $id)->get()->groupBy('month');
return view('adcr.report.modal.rent_modal', compact('report'));
}
I got Property [fiscal_year] does not exist on this collection instance. (View: C:\wamp64\www\report-management\resources\views\adcr\report\modal\rent_modal.blade.php)
How can I access this data?
This is my view:
@foreach($report as $row)
<td>{{$row->fiscal_year}}</td>
@endforeach
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
