3 回答
TA贡献1798条经验 获得超7个赞
有了这2个答案和一个小小的建议,我就得出了这个解决方案(我已经为当前月份的订单添加了一些东西作为起点):
$monthly_uploaded_product = Evenement::select(DB::raw('COUNT(id) as total, EXTRACT(MONTH FROM datedevenement) AS month')
)
->where('typeevenement_id', '1')
->wheredate('datedevenement', '>=', Carbon::now()->lastOfMonth()->subyears(1))
/// ->whereYear('datedevenement', Carbon::now()->year)
->groupBy(DB::raw('month'))
->get();
$mois = ["janvier", "fevrier", "mars", "avril", "mai", "juin", "juillet", "aout", "septembre", "octobre", "novembre", "decembre"];
foreach ($mois as $mois99) {
$arriveeparmoisrefuge[]= array(
'mois' => $mois99,
'total' => '0'
);
}
foreach ($monthly_uploaded_product as $key) {
$arriveeparmoisrefuge[$key->month - 1]['total'] = $key->total;//update each month with the total value
}
$sorted = collect($arriveeparmoisrefuge)->sortBy(function ($count, $month) {
$currentMonth = (int) \Carbon\Carbon::now()->month;
return ($month + (13 - $currentMonth - 1)) % 12;
});
return $sorted;
- 3 回答
- 0 关注
- 184 浏览
添加回答
举报