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

我正在尝试上传多个图像,但是当我在服务器上推送此代码时,它给了我 hashName 错误

如何解决我正在尝试上传多个图像,但是当我在服务器上推送此代码时,它给了我 hashName 错误

我正在尝试上传多张图片,但是当我在服务器上推送此代码时,它给了我 hashName 错误

这是错误

在 null 时调用成员函数 hashName()

HTML 代码

<form action="{{ route('products.store') }}" method="post" enctype="multipart/form-data">
        <!-- Add CSRF Token -->
        @csrf
    <div class="form-group">
        <label>Product Name</label>
        <p> le nom du theme <input type="text" class="form-control" name="name" required></p>
        </br>
        <p>la description du theme<input type="text" class="form-control" name="description" required</p>
       <div class="form-group">
       <input type="file" name="image" required>
       <input type="file" name="image2" required>
       <input type="file" name="image3" required>
       <input type="text" class="form-control" name="prix" required>
       <input type="text" class="form-control" name="nb_download" required>
       <input type="file" name="file" required>
       <button type="submit">Submit</button>
    </div>
</form>

路线:

route::resource('products','App\http\controllers\TemplatesController');

templatesController(存储函数):

 public function store(Request $request)
    {
            
            $templates = new templates([
                "name" => $request->get('name'),"description"=>$request->get('description'),"image_path"=>$request->image1->hashName(),"image_path2"=>$request->image2->hashName(),"image_path3"=>$request->image3->hashName(),"prix"=>$request->get('prix'),"file_path" => $request->file->hashName(),"nb_download"=>$request->get('nb_download')
            ]);

            $request->image1->move(public_path('images'));
            $request->image2->move(public_path('images'));
            $request->image3->move(public_path('images'));


            $templates->save(); 
            
        

        return view('products.create');

    }

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