Last active
March 27, 2022 21:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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