0

I have a User table and i successfully pulling data from database in to my view by the following controller

public function indexBloodDonation()
{

            $result = User::where('blood_group','O-')->get();
            return View::make('bloodDonation.donors')->with('result',$result);
}

but its in fact fetching all user whom blood group is O- ,but i want to pull latest 4 or 5 or 10 user,not all user from database. What should be the laravel4 eloquent query to get latest data from database?

Md. Tanvir Raihan
  • 4,075
  • 9
  • 37
  • 70
  • possible duplicate of [Is there a way to "limit" the result with ELOQUENT ORM of Laravel?](http://stackoverflow.com/questions/15229303/is-there-a-way-to-limit-the-result-with-eloquent-orm-of-laravel) (combined with an `orderBy` call) – ceejayoz Dec 15 '14 at 15:59

1 Answers1

1

Would this be what you are looking for?

public function indexBloodDonation()
{
     $result = User::where('blood_group','O-')->orderBy('created_at','desc')->take(10)->get();
     return View::make('bloodDonation.donors')->with('result',$result);
}
repptilia
  • 457
  • 8
  • 19
  • yeah i am exactly looking for this type of eloquent ORM,i will test it very soon and if it works,then i will give you the feedback.Thanks for the answer. – Md. Tanvir Raihan Dec 16 '14 at 02:29