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['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"
CodePudding user response:
Solution !
Faktor::create([
'user_id' => 1,
'product_id' => $req->get('product_id'),// here solution
'total' => 1,
]);
return redirect()->back();
CodePudding user response:
My friend is product_id solved You were great I'm so happy thanks for your help
Now it does not recognize the user and gives an error
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null