我正在从数据库中检索项目并按'MONTH'对它们进行分组:
$events = DB::table('events')->get();
$events_by_month = $events->groupBy('month');
这将返回一个如下集合:
Collection {#186 ▼
#items: array:1 [▼
"DEC" => Collection {#159 ▼
#items: array:1 [▼
0 => {#166 ▼
// attributes
}
]
},
"JAN" => Collection {#159 ▼
#items: array:1 [▼
0 => {#166 ▼
// attributes
}
]
}
]
}
我将此传递给我想要显示给定月份的项目的视图 . 我可以在这里使用 whereIn
(以及哪种情况关键是什么?)还是有其他/更好的方法?
whereIn
中没有键返回错误:
@foreach($mths->whereIn(['DEC', 'JAN']) as $mth => $events)
1 回答
在视图中: