We need to know what you are working with. Show the output of dd($cart);
Sep 1, 2022
8
Level 1
I want to add product ID in OrderProduct Table but I'm not be able to do that.
When I'm trying to put product_id it shows Undefined index: id.
$cart = Session::get('cart');
$quantity=0;
$price=0;
foreach($cart as $item){
$product_id = $item['id'];
// dd($product_id);
$quantity=$item['quantity'];
$price=$item['price'];
$total_price = $item['quantity'] * $item ['price'];
OrderProduct::insert([
'order_id' => $order_id,
// 'product_id'=> $item['id'],
'product_id'=> $product_id,
'quantity' => $quantity,
'price' => $price,
'total_price' => $total_price,
'created_at' => Carbon::now(),
]);
}
Please or to participate in this conversation.