我在表格网格中有一个表单,可在其中输入颜色,然后单击添加到网格,然后在网格中我可以按特定颜色添加多个图像。
这是我的html代码:
<div class="form-group">
<div class="col-sm-10">
<input type="text" class="form-control" id="ColorName" placeholder="Enter Color Name">
</div>
<div class="col-sm-2">
<input type="submit" class="btn btn-success" id="txtcanChangePrice" value="ADD">
</div>
</div>
<div class="form-group ">
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center">Color</th>
<th class="text-center">Image</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody class="text-center" id="tbody">
<tr>
<td class="col-sm-3"><input type="text" name="color1[]" class="form-control"></td>
<td class="col-sm-9"><input type="file" name="images1[]" class="form-control" multiple></td>
<td class="col-sm-1"><a href="javascript:;" class="deleteRow"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
<tr>
<td class="col-sm-6"><input type="text" name="color2[]" class="form-control"></td>
<td class="col-sm-2"><input type="file" name="images2[]" class="form-control" multiple></td>
<td class="col-sm-1"><a href="javascript:;" class="deleteRow"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
</tbody>
</table>
</div>
在我的控制器代码中:
foreach ($request->image1 as $images) {
foreach ($images as $key => $image) {
$image = $request->file('files')[$key];
$image->move('uploads/product/', $image->getClientOriginalName());
$data = new Image();
$data->color_id = $request->color1[$key];
$data->image = $image->getClientOriginalName();
$data->save();
}
}
在我的控制器中,我尝试仅出于测试目的而获得第一个。但是图像无法保存。顺便说一句,我想按颜色将所有图像从网格保存到数据库。