Skip to content

Instantly share code, notes, and snippets.

@bran921007
Last active March 27, 2022 21:11
Show Gist options
  • Save bran921007/95cdbd36e63be04372d176a602b87728 to your computer and use it in GitHub Desktop.
Save bran921007/95cdbd36e63be04372d176a602b87728 to your computer and use it in GitHub Desktop.
sub-query to get "total price" of an order by quantity & unit price
$orders = Order::addSelect([
'total_price' => OrderItem::whereColumn('order_id', 'orders.id')
->selectRaw('sum(quantity * price) as total_price')
])->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment