Md. Tanvir Raihan
Md. Tanvir Raihan

Reputation: 4285

laravel4 pulling latest data from database

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?

Upvotes: 0

Views: 47

Answers (1)

repptilia
repptilia

Reputation: 457

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);
}

Upvotes: 1

Related Questions