laravel 8 中的多张图片上传问题

Problem in multiple image upload in laravel 8

上传多张图片时 laravel 8 出错。

参数 1 传递给 Illuminate\Database\Grammar::parameterize()

must be of the type array, string given, called in C:\xampp\htdocs\laravel_cms\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 886

这是我在控制器中的代码:

 $gallery =  new GalleryImage; 
 foreach( $req->file('image_name') as $image)
   {
     $upload_image_name = time().'_'.$image->getClientOriginalName();
     $image->move('uploads', $upload_image_name);    
     $name[] = $upload_image_name;         
   } 
    $gallery->image_name = $name;        
    $gallery->save();         
    return redirect()->back()->with('status','Image Uploaded Successfully.');

blade中的代码:

<input name="image_name[]" id="exampleFile" type="file" accept="image/*" multiple>

如果我 return $req->file('image_name') 文件显示为空

看起来问题是由于在数据库字段中存储数组值造成的。如果您尝试以逗号分隔存储图像,那么

$gallery->image_name = implode(', ',$name);        

或 变化

 $name[] = $upload_image_name;   

 $name[]['image_name'] = $upload_image_name;

并用于存储

GalleryImage::insert($name);