我咨询了一下,我需要插入一个从视图├── Commands -> /Library/Frameworks/Mono.framework/Versions/Current/bin
├── External
├── Headers -> /Library/Frameworks/Mono.framework/Versions/Current/include
├── Home -> /Library/Frameworks/Mono.framework/Versions/Current/
├── Libraries -> /Library/Frameworks/Mono.framework/Versions/Current/lib
├── Mono -> /Library/Frameworks/Mono.framework/Versions/Current/lib/libmono-2.0.dylib
└── Versions
获得的数组,但是在控制器中执行请求时,我得到所有值都是空的。 / p>
视图
foreach
控制器
@foreach($product as $prod)
<tr>
<td>
<input type ="text" name="name[]" value="{{ $prod->name}}" readonly="readonly">
</td>
<td>
<input type="text" name="price[]" class="price" value="{{ $prod->price}}" readonly="readonly">
</td>
<td>
<input type="number" min="1" max="100" class="quantity" value="1" name="quantity[]">
</td>
</tr>
@endforeach
值的名称,价格和数量返回空值。
dd($ request)的结果返回了数组的正确值
答案 0 :(得分:0)
for
循环如下所示:
我创建了一个数组来存储数据,然后批量插入整个数组。
$now = Carbon::now()->toDateTimeString();
$data = [];
for($i= 0; $i <= 2; $i++){
$data[] = [
'created_at'=>$now,
'updated_at'=>$now,
'name' => $request->input("name[$i]"), //changed quotes type.
'price= $request->input("price[$i]")
/* similar for other fields....*/
];
}
Detail::insert($data);
答案 1 :(得分:0)
这样的事情可以帮助您
$input = $request->all();
for($i=1; $i<= count($input['quantity']); $i++) {
$data = [
'name' => $input['name'][$i],
'price' => $input['price'][$i],
'quantity' => intval($input['quantity'][$i])
];
Detail::create($data);
}