【发布时间】:2018-04-29 08:52:00
【问题描述】:
如果我有一个 Illuminate\Support\Collection,我如何使用 asc 和 desc 对多个属性进行排序? (这是一个简单的假设 - 根本不是在寻找有关查询构建的提示。)
$collection = User::all(); // not looking for User::orderBy()->get() solutions. Read the question.
$sorting_insructions = [
['column'=>'first_name', 'order'=>'asc'],
['column'=>'date_of_birth', 'order'=>'desc'],
];
$collection->sort(function($a,$b) use ($sorting_instructions){
// something...
});
【问题讨论】:
标签: php laravel sorting collections