I make order management system in laravel. This is my table structure is When user gives order The controller will fill 2 tables 1- orders , 2- orderitems in orders table there are 2 fields user_id and total (price). and in orderitems controller will create different columns for product example if user place 2 product than controller will create 2 row in orderitems table there are 5 fields order_id , product_id , quantity , price , total (for particular product)
this is my orderitems table
the doubt is that how i can add price of different columns of orderitems table and show it in total of orders table this is my OrderController
public function store(Request $request)
{
$order = Order::create([
'user_id' => $request->input('user_id'),
'total' => **Doubt here**,
]);
$size = count(collect($request)->get('quantity'));
for ($i = 0; $i < $size; $i++) {
$orderitem = Orderitem::create([
'order_id' => $order->id,
'product_id' => $request->get('product_id')[$i],
$quantity = $request->get('quantity')[$i],
'quantity' => $quantity,
$price = Product::find($request->get('product_id')[$i])->price,
'price' => $price,
'total' => $quantity * $price,
]);
}
return redirect()->route('orders.index');
}

