Laravel在更新方法中通过Cloudder和Cloudinary通过getRealPath()错误上传图像,“在null上调用成员函数getRealPath()”

时间:2018-08-24 09:01:28

标签: laravel

问题是我也使用cloudder创建产品,完成了。但是,在编辑中,错误是“在null上调用成员函数getRealPath()”

这是控制器update()方法

Cloudder::upload($request->file('images')->getRealPath(), $current_time);
    $product->images = Cloudder::getResult()['url'];
    $product->sale = $request->input('sale');
    $product->description = $request->input('description');
    $product->detail = $request->input('detail');
    $product->save();
    return redirect('/admin/product');

这里是视图,输入文件上传图片

                    <div class="row">
                        <label class="col-sm-2 label-on-left" for="inputSuccess">Upload image</label>
                        <div class="form-group">
                            <div class="row ml-1">
                                <div class="col-sm-2">
                                    <input type="file" name="images" class="mr-2" accept="image/*" onchange="readURL(this);">
                                    <span class="badge badge-green">Choose new image...</span>
                                    <img id="upload-image" src="#" alt="new image here" />
                                </div>
                                <div class="col-sm-2">
                                    <span class="badge badge-green">Previous Image</span>
                                    <img src="{{ $product->images }}" class="img-thumbnail" style="width: 150px; height: 150px;"/>
                                </div>
                                @if($errors->has('images'))
                                <label class="text-danger">*{{$errors->first('images')}}</label>
                                @endif
                            </div>
                        </div>
                    </div>

1 个答案:

答案 0 :(得分:0)

您可以使用getPathname,这是laravel SplFileInfo类扩展的UploadedFile方法

Cloudder::upload($request->file('images')->getPathname(), $current_time);