我的laravel版本const VERSION ='5.4.15';
HomeController的
$collection = collect([
['name' => 'Desk', 'price' => 200],
['name' => 'Chair', 'price' => 100],
['name' => 'Bookcase', 'price' => 150],
]);
$sorted = $collection->sortBy('price');
$sorted->values()->all();
return $sorted;
Run Code Online (Sandbox Code Playgroud)
以JSON格式返回时的结果:
{
0: {
name: "Desk",
price: 200
},
1: {
name: "Chair",
price: 100
},
2: {
name: "Bookcase",
price: 150
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?为什么不sortBy工作?
| 归档时间: |
|
| 查看次数: |
1001 次 |
| 最近记录: |