score:0

you can use pluck() instead of get() for this:

$prd = db::table('order_details')
    ->join('products', 'order_details.product_id', '=', 'products.id')
    ->select('products.name', db::raw('sum(quantity) as quantity'))
    ->groupby('products.name')
    ->orderby('quantity', 'desc')
    ->pluck('name', 'quantity');

Related Query

More Query from same tag