Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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();
Source by laravel.io #
 
PREVIOUS NEXT
Tagged: #sort #number #views #descending #laravel
ADD COMMENT
Topic
Name
5+2 =