Skip to content

Instantly share code, notes, and snippets.

@the7th
Last active March 6, 2018 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the7th/613ec099f36fddbb13184239fc94b4b2 to your computer and use it in GitHub Desktop.
Save the7th/613ec099f36fddbb13184239fc94b4b2 to your computer and use it in GitHub Desktop.
Laravel Eloquent LIMIT
<?php
// below is just a sample code
$specificProject = DB::table('projects')
->select('projects.id', 'projects.project_name', 'projects.progress_percent', 'projects.project_note_id', 'projects.project_status', 'project_notes.notes', 'project_timeline.start_date', 'project_timeline.end_date', 'assigned_project.id', 'assigned_project.project_assigned_to_user', 'users.name')
->join('project_notes', 'projects.id', '=', 'project_notes.project_id')
->join('project_timeline', 'projects.id', '=', 'project_timeline.project_id')
->join('assigned_project', 'projects.id', '=', 'assigned_project.project_id')
->join('users', 'assigned_project.project_assigned_to_user', '=', 'users.id')
->orderBy('project_notes.id', 'DESC')
->take(1) // this is the limit function in Laravel Eloquent
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment