如何在Laravel 4中对多列使用Order By? [英] How to Use Order By for Multiple Columns in Laravel 4?
本文介绍了如何在Laravel 4中对多列使用Order By?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用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中对多列使用Order By?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文