Laravel雄辩:所有()的订购结果 [英] Laravel Eloquent: Ordering results of all()
本文介绍了Laravel雄辩:所有()的订购结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只需要订购来自这个电话的结果
$ results = Project :: all();
其中项目
是一个模型。我试过这个
$ results = Project :: all() - > orderBy(name);
但它没有工作。从表中获取所有数据并获得订单的更好的方法是什么?
解决方案
您可以在查询中实际执行此操作。
$ results = Project :: orderBy('name') - > get();
这将以正确的顺序返回所有结果。
I'm stuck on a simple task. I just need to order results coming from this call
$results = Project::all();
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雄辩:所有()的订购结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文