'Delete video from Cloudinary not working in Laravel
I can delete the images from Cloudinary, but the videos are not deleted.
Controller
public function update(Request $request, $id)
{
$post = Post::find($id);
if ($request->has('video')) {
$file = $request->file('video');
$result = $file->storeOnCloudinary('Blog');
$uploadedFileUrl = $result->getSecurePath();
$uploadedFileId = $result->getPublicId();
if (isset($post->imageFileId)) {
Cloudinary::destroy($post->imageFileId);
}
if (isset($post->videoFileId)) {
Cloudinary::destroy($post->videoFileId);
}
$update = [
'video' => $uploadedFileUrl,
'videoFileId' => $uploadedFileId,
'image' => null,
'imageFileId' => null,
];
$post->update($update);
}
}
Solution 1:[1]
add resource_type Cloudinary::destroy($post->videoFileId, ["resource_type" => "video"]);
Controller
public function update(Request $request, $id)
{
$post = Post::find($id);
if ($request->has('video')) {
$file = $request->file('video');
$result = $file->storeOnCloudinary('Blog');
$uploadedFileUrl = $result->getSecurePath();
$uploadedFileId = $result->getPublicId();
if (isset($post->imageFileId)) {
Cloudinary::destroy($post->imageFileId);
}
if (isset($post->videoFileId)) {
Cloudinary::destroy($post->videoFileId, ["resource_type" => "video"]);
}
$update = [
'video' => $uploadedFileUrl,
'videoFileId' => $uploadedFileId,
'image' => null,
'imageFileId' => null,
];
$post->update($update);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
