laravel 5.2-Model :: all()排序 [英] laravel 5.2 - Model::all() order by

查看:336
本文介绍了laravel 5.2-Model :: all()排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到具有以下内容的模型的完整集合:

I get the full collection of a Model with the following:

$ posts = Post :: all();

但是我希望这是反向时间顺序。

However I want this is reverse chronological order.

什么是最好的方法

推荐答案

$posts = Post::orderBy('created_at', 'desc')->get();

您可以使用orderBy方法。用所需的名称替换列名称。

You can use the orderBy method. Replace the column name with the one you want.

这篇关于laravel 5.2-Model :: all()排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆