问题
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') }}
Which gets the object which have the highest bid_amount
value.
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.
回答1:
You may try this
Bid::where('auction_id', '=', $auction->id)
->orderBy('bid_amount', 'DESC')
->take(4)
->get();
来源:https://stackoverflow.com/questions/19835362/laravel-getting-largest-object-based-on-attribute-value