1 回答
TA贡献1784条经验 获得超2个赞
您正在尝试使用自己作为索引来访问数组。应该是$products[$product],不是$products[$products]
public function store(Request $request)
{
$order = Order::create($request->all());
$products = $request->input('products', []);
$quantities = $request->input('quantities', []);
for ($product = 0; $product < count($products); $product++)
{
if ($products[$product] != '')
{
$order->products()->attach($products[$product], ['quantity' => $quantities[$product]]);
// $products[$product], without the 's'
Product::where('id', $products[$product])->increment('qty',$quantities[$product]);
}
}
return redirect()->route('orders.index');
}
- 1 回答
- 0 关注
- 85 浏览
添加回答
举报