In my Laravel project I am preforming a database query where I search through my media table and grab all results that belong to a user_id. The results are ordered by most votes in descending order. However, this returns all the users images. I only want to grab the first 4 results, not all. How can this be done?
My media table looks like this.
| id | user_id | url | votes |
My controller looks like this
public function getUserImagesByVote($user_id)
{
return Media::where('user_id', $user_id)->orderBy('votes', 'DESC')->get();
}