我有一个用户表,并且我通过以下 Controller 成功地将数据从数据库提取到我的 View 中
public function indexBloodDonation()
{
$result = User::where('blood_group','O-')->get();
return View::make('bloodDonation.donors')->with('result',$result);
}
但它实际上获取所有血型为 O- 的用户,但我想提取最新 4 或 5 或 10 个用户,而不是数据库中的所有用户。 从数据库获取最新数据的 laravel4 Eloquent 查询应该是什么?
最佳答案
这就是您要找的吗?
public function indexBloodDonation()
{
$result = User::where('blood_group','O-')->orderBy('created_at','desc')->take(10)->get();
return View::make('bloodDonation.donors')->with('result',$result);
}
关于mysql - laravel4 从数据库中提取最新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27487964/