Reputation: 1500
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.
Upvotes: 4
Views: 7011
Reputation: 558
If you have Order and OrderList Eloquent Models, you can try something like this from a controller.
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;
Upvotes: 1
Reputation: 21681
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 !!!
Upvotes: 4