我使用
cloudinary
方法将图像上传到upload
:
public function store(StoreProductRequest $request)
{
$name = cloudinary()->upload($request->file('image')->getRealPath())->getSecurePath();
Product::create([
...
"imageUrl" => $name,
]);
}
这会将图像cloudinary url保存在
imageUrl
字段中,在update
方法中,我想获取正在更新的产品图像的公共ID(如果存在):
public function update(UpdateProductRequest $request, Product $product)
{
$imagePublicId = ??;
if($request->input('image')){
Cloudinary::destroy($imagePublicId);
}
...
}
如何获取图片的public id并删除它?