I want to add table grid dynamically with one color and multiple image but in controller for loop i get undefined offset:2 error
here is my grid html code:
<div class="form-group">
<label class="col-sm-2 control-label">Image</label>
<input type="number" class="form-control" name="imgcolor[]" />
<div class="field col-sm-10" align="left">
<input type="file" class="files" name="image[0][]" multiple />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Image</label>
<input type="number" class="form-control" name="imgcolor[]" />
<div class="field col-sm-10" align="left">
<input type="file" class="files" name="image[1][]" multiple />
</div>
</div>
in my controller code:
$input = $request->all();
$color = $request->input('imgcolor');
for($i=0; $i = count($input['imgcolor']); $i++) {
for($j=0; $j = count($request->image[$i]); $j++) {
$data = $request->file('image')[$i][$j];
$imagename = $data->getClientOriginalName();
dd($data);
$data->move('uploads/product/', $imagename);
Image::create([
'product_id' => $product->id,
'color_id' => $color[$i],
'image' => $imagename
]);
}
}
actually i need to store data in image table like one color multiple images.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire