Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User::select('users.*', DB::raw("SELECT MAX(id) FROM posts WHERE posts.firebase_id = users.firebase_id as recent_post_date"))
- ->whereHas('posts', function ($q) {
- $q->withCount('comments');
- })
- ->with(['posts' => function ($q) {
- $q->withCount('comments')
- ->orderBy('created_at', 'ASC');
- }])
- ->orderBy('recent_post_date', 'DESC')
- ->get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement