微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法将所有图像传递给 Laravel 和 Vue js 前端的控制器

如何解决无法将所有图像传递给 Laravel 和 Vue js 前端的控制器

我正在努力将图像从 vue 组件传递到 Laravel 控制器,但我只能在 Laravel 中添加一张图像。再次无法将该图像移动到图像路径。我的代码能够捕获多个图像,但我的问题是如何将它们正确传递给控制器​​。这是我的代码 视图

let selectedFiles=e.target.files;
    if(!selectedFiles.length){
     return false;
         }
      for(let i=0;i<selectedFiles.length;i++){
            this.images=selectedFiles[i];
        }
        console.log(this.images);
       },saveImageData(){
           var self=this;

          const config = {
                headers: { 'content-type': 'multipart/form-data' }
            }
 
            let formData = new FormData();
            formData.append('title',this.title);
            formData.append('description',this.description);
            formData.append('location',this.location);
            formData.append('price',this.price);
            formData.append('images',this.images);
            axios.post('/senddata',formData,config)
            .then(function (response) {
               // currentObj.success = response.data.success;
            })

在 Laravel 控制器中:

public function store(Request $request)
    {
          $product=Products::create([
         'title'=>$request['title'],'description'=>$request['description'],'price'=>$request['price'],'location'=>$request['location']
             ]);
          $images= $request->file('images');
         //dd($images->getClientOriginalName());
          foreach ($images as $image){
           $move=$image->move(public_path().'/images2/',$image->getClientOriginalName()); 
         if($move){
         $imagedata=Images::create([
        'title'=>$image->getClientOriginalName(),'filename'=>$image->getClientOriginalName()
        ]);
         $product->images()->attach([$imagedata->id]);
          }
         }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。