Ich habe diese Sammlung Ergebnis:Laravel Art Sammlung von Datum
$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
}]
Ich mag das Ergebnis nach Datum sortieren:
$sorted = $transaction->sortBy('date')->values()->all();
Aber ich habe nicht das erwartete Ergebnis:
[{
"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"
}]
Wie Sie sehen können alle mit Monat 2 ist richtig sortieren. Jedoch im Monat 3 beginnt es versaut. (Das tatsächliche Ergebnis ist länger als das und es verpatzt Start um Monat 3)
Jede Lösung, um es richtig zu sortieren?
Danke.
, was die Art der Spalte 'date' haben? –
@ChetanAmeta Hallo. Datumstyp ist String – ssuhat
Funktioniert 'orderBy (' date ',' ASC ')? –