samedi 3 décembre 2022

Laravel - how to group a Date string on table using collection

i want to group my date Month but i don't know how to do that. i try used groupBy() but its giving me a error

$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;

error : Call to a member function groupBy() on string

without groupby this is the output :

[
"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"
]

i want to group "Oct", "Nov", "Dec"



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire