Laravel sort collection by date
<p>I have this collection result:</p>

<pre><code>$result = [{
    "date": "2016-03-21",
    "total_earned": "101214.00"
},
{
    "date": "2016-03-22",
    "total_earned": "94334.00"
},
{
    "date": "2016-03-23",
    "total_earned": "96422.00"
},
{
    "date": "2016-02-23",
    "total_earned": 0
},
{
    "date": "2016-02-24",
    "total_earned": 0
},
{
    "date": "2016-02-25",
    "total_earned": 0
}]
</code></pre>

<p>I want to sort the result by date:</p>

<pre><code>$sorted = $transaction-&gt;sortBy('date')-&gt;values()-&gt;all();
</code></pre>

<p>But I don't get the expected result:</p>

<pre><code>[{
    "date": "2016-02-23",
    "total_earned": 0

},
{
    "date": "2016-02-24",
    "total_earned": 0
},
{
    "date": "2016-02-25",
    "total_earned": 0
},
{
    "date": "2016-03-22",
    "total_earned": "94334.00"
},
{
    "date": "2016-03-21",
    "total_earned": "101214.00"
},
{
    "date": "2016-03-23",
    "total_earned": "96422.00"
}]
</code></pre>

<p>As you can see all with month 2 is sort properly. However at month 3 it start messed up. (the real result is longer than this and it messed up start at month 3)</p>

<p>Any solution to make it sort properly?</p>

<p>Thanks.</p>