i have posts
table and related with likes
table ,comments
table and shares
table
i use
JavaScript
x
`Post::withCount("likes")->orderByDesc("likes_count")->paginate($per_page);`
to get posts order by likes count .
JavaScript
**i need to get posts order by maxcount of(likes + comments +shares)** ?
ِAny Suggesstion ?
Advertisement
Answer
You can use orderByRaw method
JavaScript
Post::withCount(['likes', 'comments', 'shares'])
->orderByRaw('likes_count + comments_count + shares_count DESC')
->paginate($per_page);