Ok sir, But can i access all database field with this query?

|
ilovecodingbd 2022-05-20 16:02:44
this is my controller code
ilovecodingbd 2022-05-20 16:03:12
public function RentCertificate(){
$report = Report::orderBy(‘created_at’,’desc’)
->get()
->groupBy(function (Report $item) {
return $item->created_at->format(‘Y-m’);
});
return view(‘adcr.report.rent_certificate’, $data);
}
ilovecodingbd 2022-05-20 16:03:35
this is my view code
ilovecodingbd 2022-05-20 16:03:49
@foreach(report as $month=> $item)
@foreach($item as $data)
<tr role=”row” class=”odd”>
<td>{{ $data[‘fiscal_year’] }}</td>
<td>{{ $data[‘month’]}}</td>
<td><a href=”” class=”btn btn-success”>View</a></td>
</tr>
@endforeach
@endforeach
ilovecodingbd 2022-05-20 16:04:02
Please help me
Rahul Kahar 2022-05-20 16:08:57
Why are you write group By after get??
ilovecodingbd 2022-05-20 16:09:41
Because I want to show data by monthly wise
Rahul Kahar 2022-05-20 16:10:13
So write before get method
ilovecodingbd 2022-05-20 16:10:44
Ok sir I check it now if it doesn’t work I will message.
Rahul Kahar 2022-05-20 16:10:54
Ok
ilovecodingbd 2022-05-20 16:11:20
ErrorException
stripos() expects parameter 1 to be string, object given
ilovecodingbd 2022-05-20 16:11:42
$report = Report::orderBy(‘created_at’,’desc’)
->groupBy(function (Report $item) {
return $item->created_at->format(‘Y-m’);
})
->get();
ilovecodingbd 2022-05-20 16:12:49
Rahul Sir I try this method now I got error
Rahul Kahar 2022-05-20 16:12:51
Screen shot please
ilovecodingbd 2022-05-20 16:13:25
laravel_discuss-121451.jpg

ilovecodingbd 2022-05-20 16:15:57
laravel_discuss-121452.jpg
This is my database. I want show monthly wise data. I’m very new in laravel so I can’t please help me to get the data monthly wise
Rahul Kahar 2022-05-20 16:16:22
Ok wait
ilovecodingbd 2022-05-20 16:17:09
Rahul Ok sir
DesolatorMagno 2022-05-20 16:18:23
ilovecodingbd 2022-05-20 16:03:12
public function RentCertificate(){
$report = Report::orderBy(‘created_at’,’desc’)
->get()
->groupBy(function (Report $item) {
return $item->created_at->format(‘Y-m’);
});
return view(‘adcr.report.rent_certificate’, $data);
}

When you do group by after you did the get you are grouping the collection not in the database query, which is a lot slower and different.

Rahul Kahar 2022-05-20 16:19:56
$report = Report::orderBy(‘created_at’,’desc’)
->get() ;
$report->groupBy(function (Report $item) {
return $item->created_at->format(‘Y-m’);
});
Rahul Kahar 2022-05-20 16:20:07
Try this
ilovecodingbd 2022-05-20 16:20:17
Ok sir
Rahul Kahar 2022-05-20 16:21:57
$report = Report::orderBy(‘created_at’,’desc’)
->get() ;
$report->groupBy(function ($item,$key) {
return $item->created_at->format(‘Y-m’);
});
Rahul Kahar 2022-05-20 16:22:14
If above code not work then try this
ilovecodingbd 2022-05-20 16:22:30
Sir I got now
ilovecodingbd 2022-05-20 16:23:10
ErrorException
Undefined variable: report (View: C:wamp64wwwreport-managementresourcesviewsadcrreportrent_certificate.blade.php)
Rahul Kahar 2022-05-20 16:23:26
Ok 👍 continue
Rahul Kahar 2022-05-20 16:24:50
After above code $resport variable assign with another variable with get() method
ilovecodingbd 2022-05-20 16:25:16
Sir I try your given method but I can see Month is differently show,
ilovecodingbd 2022-05-20 16:25:46
laravel_discuss-121467.jpg

ilovecodingbd 2022-05-20 16:26:59
Sir Please help me to get data as monthly wise
ilovecodingbd 2022-05-20 16:28:02
DesolatorMagno 2022-05-20 16:18:23
When you do group by after you did the get you are grouping the collection not in the database query, which is a lot slower and different.

What is the best way to get the data monthly wise? I’m very new so I don’t understand sir

Rahul Kahar 2022-05-20 16:28:23
->select(DB::raw(‘count(id) as data’), DB::raw(“DATE_FORMAT(created_at, ‘%m-%Y’) new_date”), DB::raw(‘YEAR(created_at) year, MONTH(created_at) month’))
->groupby(‘year’,’month’)
->get();
Rahul Kahar 2022-05-20 16:28:51
Use this code -> another solution
ilovecodingbd 2022-05-20 16:29:49
Ok sir, But can i access all database field with this query?
|