Php 我只想在用户使用laravel选择新图片时更新图像列

Php 我只想在用户使用laravel选择新图片时更新图像列,php,laravel-5,Php,Laravel 5,图像存储功能 ProductController.php public function store_image(Request $request, $id) { $image = Product::find($id); $imageupdate = $request->all(); for ($i = 1; $i < 6; $i++) { $n = 'photo_' . $i; if ($file = $request-&g

图像存储功能

ProductController.php

public function store_image(Request $request, $id) {
    $image = Product::find($id);
    $imageupdate = $request->all();

    for ($i = 1; $i < 6; $i++) {
        $n = 'photo_' . $i;
        if ($file = $request->file($n)) {
            $name = time() . $file->getClientOriginalName();
            $file->move('img/products', $name);
            /*two parameter of move function are 1. name of directory and 
              2.name of the file to store*/
            $imageupdate['photo_' . $i] = $name;
        }
    }
}
公共函数存储\u映像(请求$Request,$id){
$image=Product::find($id);
$imageupdate=$request->all();
对于($i=1;$i<6;$i++){
$n='photo_uu'.$i;
如果($file=$request->file($n)){
$name=time().$file->getClientOriginalName();
$file->move('img/products',$name);
/*移动函数的两个参数是1.目录名和
2.要存储的文件的名称*/
$imageupdate['photo.'$i]=$name;
}
}
}
SQL中产品的表:


实际要求是什么?你的问题不是在解释问题requirement@MayankPandeyz我有一个表单,其中我只显示我的照片,如果用户希望编辑照片,他可以添加一张新照片,但我编写的代码会替换所有字段,即使用户仅选择照片,例如,如果用户只想更改第一个字段,则用户现在有5个字段中的3个要替换的照片然后到所有字段被替换,字段2和3列中的现有图片在数据库中被null覆盖