public function store(Request $request)
{
$order = Order::create([
'user_id' => $request->input('user_id'),
'total' => 0,
]);
$total = 0;
$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,
]);
$total += $orderitem['quantity']*$orderitem['price'];
}
$order['total'] = $total;
$order->save()
return redirect()->route('orders.index');
}