Can't get sortBy to work with a timestamp - getting wrong order

Posted 3 months ago by MartinZeltin

I have an array that I converted to a Collection with collect($array) and then tried to sort it by activity_time but it's not sorting it.

$latest_activities = collect($latest_activities)->sortByDesc('activity_time');

But I'm getting this result:

{
    "0": {
        "activity_time": "2019-04-29 12:03:15",
        "activity_title": "User logged in",
    },
    "1": {
        "activity_time": "2019-04-29 11:59:07",
        "activity_title": "User opened profile page",
    },
    "2": {
        "activity_time": "2019-04-16 17:35:50",
        "activity_title": "User logged out",
    },
    "3": {
        "activity_time": "2019-04-29 11:56:40",
        "activity_title": "User commented on",
    }
}

Please sign in or create an account to participate in this conversation.