在Laravel 5中按行排序和限制结果 [英] Order by row and limit result in Laravel 5

查看:111
本文介绍了在Laravel 5中按行排序和限制结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从基于laravel 5的应用程序中的数据库中获取结果,而我一生无法解决.

I'm trying to get a result from the database in a laravel 5 based application and for the life of me can't figure it out.

我想从称为count的行中选择前5个结果DESC. 这就是我所拥有的:

I want to chose the top 5 results DESC from a row called count. This is what I have:

$full = Fulls::all()->orderBy('count', 'desc')->take(5)->get();

我也尝试了许多其他方法,但似乎无济于事.现在我遇到一个错误:

I tried plenty of other ways too but nothing seems to work. Now I'm getting an error:

indexController.php第19行中的

FatalErrorException:调用未定义 方法Illuminate \ Database \ Eloquent \ Collection :: orderBy()

FatalErrorException in indexController.php line 19: Call to undefined method Illuminate\Database\Eloquent\Collection::orderBy()

但是,在我所看到的任何地方,我看到有人在使用orderBy()工作,所以...我在做什么错了?

However, anywhere I look I see people working with orderBy(), so... what am I doing wrong?

预先感谢...

推荐答案

您应该改用Fulls::orderBy(..)->take(5)->get().

这篇关于在Laravel 5中按行排序和限制结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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