Laravel Eloquent:all() 的排序结果 [英] Laravel Eloquent: Ordering results of all()
本文介绍了Laravel Eloquent:all() 的排序结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被困在一个简单的任务上.我只需要订购来自此调用的结果
I'm stuck on a simple task. I just need to order results coming from this call
$results = Project::all();
Project
是一个模型.这个我试过了
Where Project
is a model. I've tried this
$results = Project::all()->orderBy("name");
但它没有用.从表中获取所有数据并对其进行排序的更好方法是什么?
But it didn't work. Which is the better way to obtain all data from a table and get them ordered?
推荐答案
您实际上可以在查询中执行此操作.
You can actually do this within the query.
$results = Project::orderBy('name')->get();
这将以正确的顺序返回所有结果.
This will return all results with the proper order.
这篇关于Laravel Eloquent:all() 的排序结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文