sort by number of views descending laravel code example
Example: sort by number of views descending laravel
$posts = Post::select(DB::raw('posts.*, count(*) as `aggregate`'))
->join('views', 'posts.id', '=', 'views.post_id')
->groupBy('post_id')
->orderBy('aggregate', 'desc')
->get();