$January = $articles->whereMonth('updated_at','01')
->whereYear('updated_at', $year)
->get();
$February = $articles->whereMonth('updated_at','02')
->whereYear('updated_at', $year)
->get();
如果$January
中没有数据,则将空数组写入$February
,而不考虑数据的可用性。告诉我如何解决它,为什么会这样?
答案 0 :(得分:0)
之前有类似的question回答
您需要像这样在clone
上使用$articles
:
$January = (clone $articles)->whereMonth('updated_at','01')
->whereYear('updated_at', $year)
->get();
$February = (clone $articles)->whereMonth('updated_at','02')
->whereYear('updated_at', $year)
->get();