iam sitting here since 9am and breaking my head about this weird stuff.
Im trying to group a collection of entries
by the year and month of created_at
.
My code looks like this:
Auth::user()
->entries()
->get()
->sortByDesc('created_at')
->groupBy(
[
function($item) {
return $item->created_at->year;
},
function($item) {
return $item->created_at->month;
},
]
)
->sortKeysDesc()
But all I get is this:
{
"2018": {
"12": [
{
"id": 8,
"user_id": 1,
"name": "et",
"value": -8.6,
"created_at": "2018-12-31 20:59:06",
"updated_at": "2019-02-03 19:50:20"
},
…
]
},
"2019": {
"1": [
{
"id": 42,
"user_id": 1,
"name": "non",
"value": -3.5,
"created_at": "2019-01-31 05:36:01",
"updated_at": "2019-02-03 19:50:20"
},
…
]
}
}
My target is to get the latest years at first. 2019, 2018… As you can see, the sortKeysDesc()
doesn't do anything at all. Yes – i tried sortKeys()
as well -> same result.
Whats wrong with my approach?
Thank you.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire