Level 122
Dump kickoff and check it is seeing the right value
$sorted = $merged->sortBy(function($col) {
dump($col->kickoff);
return $col->kickoff;
});
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am merging two collection objects and I can't get it sorted by a date field.
I've tried
$one->merge($two)->sortBy('kickoff')
Merged, but not sorting Also tried
$merged = $one->merge($two);
$sorted = $merged->sortBy(function($col) {
return $col->kickoff;
})->values()->all();
Nothing seems to be sorting by the kickoff date as I expect.
kickoff is an attribute of format:
[kickoff] => 2018-07-07 19:30:00
Why doesn't laravel sortBy work ?
Please or to participate in this conversation.