Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement