我从控制器的视图($ rquest)中收到了此数据表格{} 如何在带有x个项{}的产品数组中获取“ product_id”值以在控制器中使用它们?
form: {
id: null,
sale_number: 2,
client: null,
products: [
{ product_id:1,description: null, quantity:1, price: 1}
{ product_id:2,description: null, quantity:1, price: 1}
{ product_id:3,description: null, quantity:1, price: 1}
.....etc
],
}
答案 0 :(得分:1)
您可以使用$request->products
和foreach
foreach($request->products as $product)
{
$product['product_id']
}
如果要将它们保存在数组中,请执行此操作
$product_id_array = array();
foreach($request->products as $product)
{
product_id_array[] = $product['product_id'];
}