GroupBy clause with multiple columns select in laravel

Submitted by sanjok1988 - 1 month 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()
    );
});