【发布时间】:2018-06-22 06:17:15
【问题描述】:
我正在尝试创建一个显示每月数据的 morrisJS 折线图。 所以我每月得到这样的数据:
$intakes = Intakes::whereYear('created_at', '=', 2018)
->orWhere(function ($query) {
$query->whereMonth('created_at', '=', 1)
->whereMonth('created_at', '=', 2)
->whereMonth('created_at', '=', 3)
->whereMonth('created_at', '=', 4)
->whereMonth('created_at', '=', 5)
->whereMonth('created_at', '=', 6)
->whereMonth('created_at', '=', 7)
->whereMonth('created_at', '=', 8)
->whereMonth('created_at', '=', 9)
->whereMonth('created_at', '=', 10)
->whereMonth('created_at', '=', 11)
->whereMonth('created_at', '=', 12);
})
->get();
但这将返回所有记录,范围从第 1 个月到第 12 个月。但我想要的是每月的数据,除了像这样创建多个变量之外还能实现吗?
$intakesMonth1 = Intakes::whereYear('created_at', '=', 2018)
->whereMonth('created_at', '=', 1)
->get();
$intakesMonth2 = Intakes::whereYear('created_at', '=', 2018)
->whereMonth('created_at', '=', 2)
->get();
我希望我足够清楚,并且有人知道更好的解决方案。
【问题讨论】:
标签: javascript php jquery laravel morris.js