我想分组我的日期月,但我不知道如何做到这一点。我尝试使用groupBy()
,但它给我一个错误
$user = Auth::user()->id;
$date = productSold::where('user_id',$user)->get();
$collect = collect($date)->map(function ($date) {
return date('M',strtotime($date->created_at))->groupBy('created_at');
});
return $collect;
错误:对字符串调用成员函数groupBy()
如果不使用groupby,则输出如下:
[
"Oct",
"Oct",
"Nov",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec",
"Dec"
]
我想对"Oct", "Nov", "Dec"
进行分组
1条答案
按热度按时间06odsfpq1#
它的错误是因为你从一个字符串中按它分组。所以你应该从map函数中取出groupBy语句。所以结果应该是这样的:
结果应该类似于this。