Level 73
So you see there is no id in your array.. you should get the product_id instead
'product_id' => $product['product_id'],
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
ERROR: Undefined array key "id" in form
@ php
$total = 0
@ endphp
@ if(session('cart'))
@ foreach(session('cart') as $id => $details)
@ php $total += $details['price'] * $details['quantity'] @endphp
<input type="hidden" name="product_id" value="{{ $id }}" >
{{ $id }}
<input type="hidden" name="name" value="{{ $details['name'] }}">
{{ $details['name'] }}
<input type="hidden" name="quantity" value="{{ $details['quantity'] }}">
{{ $details['quantity'] }}
<input type="hidden" name="price" value="{{ $details['price'] }}">
{{ $details['price'] }}
@endforeach
in controller
public function ad(Request $request)
{
$product = $request->session()->get('cart');
// dd($product);
Faktor::create([
'user_id' => 1,
'product_id' => $product['product_id'],-->ERROR: Undefined array key "id"
'total' => 1,
]);
return redirect()->back();
dd($product);
^ array:2 [▼
1 => array:5 [▼
"product_id" => 1
"name" => "ssd samsumg "
"quantity" => 1
"price" => "1000"
"image" => "20221014072724.jpg"
So you see there is no id in your array.. you should get the product_id instead
'product_id' => $product['product_id'],
Please or to participate in this conversation.