我有一个带有“created_at”属性的 Laravel 集合,我想按年份过滤,就像在 eloquent 中一样:$model->whereYear()但是在一个集合中。谢谢!#attributes: array:10 [ "id" => 720 "created_at" => "2019-05-15 08:24:00" "updated_at" => "2019-05-15 08:24:00" ]
1 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
您可以使用 Collections 方法过滤器来仅查找年份符合您条件的那些:
$collection = Model::all();
$collection->filter(function ($value) {
return $value->created_at->year === 2019; // assuming, that your timestamp gets converted to a Carbon object.
});
- 1 回答
- 0 关注
- 194 浏览
添加回答
举报
0/150
提交
取消