public function ad(Request $request)
{
$products = $request->session()->get('cart');
foreach ($products as $product) {
Faktor::create([
'user_id' => Auth::id(),
'product_id' => $product['product_id'],
'name' => $product['name'],
'quantity' => $product['quantity'],
'price' => $product['price'],
]);
}
return redirect('bill');
}
when i show invoice to user , it is a invoice include one user name and one user mobile and many products . how i can show invoce without foreach with foreach for each id show one invoice
id user_id product_id name price 1 1 2 ssd 1000 2 1 1 i9 gen12 1000
@ foreach($invoice as $item)
{{ $item->user->name }}
{{ $item->name }}
{{ $item->price}}
thank you for your help
or How i can store data in array
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