如何在 Laravel 4 中对多列使用排序依据? [英] How to Use Order By for Multiple Columns in Laravel 4?
本文介绍了如何在 Laravel 4 中对多列使用排序依据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 Laravel Eloquent 中的 orderBy()
方法对 Laravel 4 中的多列进行排序.查询将使用 Eloquent 生成,如下所示:
I want to sort multiple columns in Laravel 4 by using the method orderBy()
in Laravel Eloquent. The query will be generated using Eloquent like this:
SELECT *
FROM mytable
ORDER BY
coloumn1 DESC, coloumn2 ASC
我该怎么做?
推荐答案
只需根据需要多次调用 orderBy()
.例如:
Simply invoke orderBy()
as many times as you need it. For instance:
User::orderBy('name', 'DESC')
->orderBy('email', 'ASC')
->get();
产生以下查询:
SELECT * FROM `users` ORDER BY `name` DESC, `email` ASC
这篇关于如何在 Laravel 4 中对多列使用排序依据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文