GroupBy clause with multiple columns select in laravel

Submitted by sanjok1988 - 4 years ago

GroupBy clause with multiple columns select in laravel

Route::get('test', function () {
    return response(
        DB::table('articles')
        ->select(DB::raw('Max(articles.title) as title, articles.category_id as
        cid'))
        ->distinct('category_id')
        ->groupBy('category_id')

        ->orderBy('title', 'desc')

        ->get()
    );
});