Laravel查询以获取具有最大数量的前10条记录



我想根据最大数量获取前 10 条记录。我已经尝试过使用以下代码

1)  $topclaims = Claim::take(10)->max('estimated_loss')->get()   
// giving me an error Call to a member function get() on string
2)  $topclaims = Claim::take(10)->orderBy('estimated_loss','DESC')->get();
//this one is working but not getting an exact result
3) $topclaims = Claim::orderBy('estimated_loss','DESC')->limit(10)->get(); 
//this one is also working but not getting an exact result

我想要这样

first record = 10,
second = 9,
third = 8,
fourth = 7,
fifth = 6

the result I am getting is 
first record = 9,
second = 8,
third = 10,
fourth = 6,
fifth = 7

您必须先将estimated_loss转换为 int 才能排序。

$topclaims = Claim::orderByRaw("CAST(estimated_loss as UNSIGNED) DESC")->limit(10)->get(); 

最新更新