[英]How to multiply two columns from two different table with eloquent in laravel
order 订购
currency 货币
order_list 订单
I want the following output: 我想要以下输出:
Here I want to multiply the ex_rate_with_base
field of order table with unit_price
of order_list table using eloquent. 在这里,我要乘
ex_rate_with_base
顺序表的字段unit_price
用雄辩order_list表。
I think you can try this: 我想你可以试试这个:
DB::table('order')
->select(DB::raw('(order.ex_rate_with_base * order_list.unit_price_in_base_currency) as orderRate'))
->leftjoin('order_list','order_list.order_id','=','order.id)
->get();
Hope this work for you !!! 希望这对你有用!!!
If you have Order and OrderList Eloquent Models, you can try something like this from a controller. 如果你有Order和OrderList Eloquent Models,你可以从控制器尝试这样的东西。
YourOrderController.php YourOrderController.php
$order= Order::find($orderId);
$orderList = OrderList::where('order_id',$orderId)->get();
$calculatedPrice = $orderList->unit_price_in_base_currency * $order->ex_rate_with_base;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.