Guest User

Untitled

a guest
Aug 14th, 2019
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. User::select('users.*', DB::raw("SELECT MAX(id) FROM posts WHERE posts.firebase_id = users.firebase_id as recent_post_date"))
  2. ->whereHas('posts', function ($q) {
  3. $q->withCount('comments');
  4. })
  5. ->with(['posts' => function ($q) {
  6. $q->withCount('comments')
  7. ->orderBy('created_at', 'ASC');
  8. }])
  9. ->orderBy('recent_post_date', 'DESC')
  10. ->get();
RAW Paste Data