Laravel-根据属性值获取最大的对象 [英] Laravel - getting largest object based on attribute value

查看:96
本文介绍了Laravel-根据属性值获取最大的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图根据其中的一个属性来获取四个最高的对象.

I have been trying to get the four highest objects based on an attribute in them.

通过执行以下操作,我可以成功获得价值最高的商品:

I can successfully get the one with the highest value by doing the following:

{{ Bid::where('auction_id', '=', $auction->id)->max('bid_amount') }}

哪个获取具有最高bid_amount值的对象.

Which gets the object which have the highest bid_amount value.

现在,我可能可以循环浏览所有出价,但是Laravel必须有一种更聪明的方式来完成此操作,而我无法在他们的文档中找到它.

Now I could potentially make a loop and loop all bids through but Laravel must have a smarter way of doing it and I have not been able to find this in their documentation.

推荐答案

您可以尝试

Bid::where('auction_id', '=', $auction->id)
    ->orderBy('bid_amount', 'DESC')
    ->take(4)
    ->get();

这篇关于Laravel-根据属性值获取最大的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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