Closed hotfuzz123 closed 2 years ago
@hotfuzz123 I think the only way you can do this right now is if you are storing the public_id(which could be the filename) of the uploaded file in your database. Then you can use that to delete the resource from Cloudinary by supplying the public_id
to the destroy()
method of the Cloudinary API.
So the flow could be something like this (using the example of a user updating their profile picture):
public_id
or file_name
attached to the user in the users
table or the media
table which comes with the Cloudinary package.public_id
to make a destroy
call to delete the previous image.Something along these lines should probably work.
@dela-dels I can't find the public_id - The error is: "Missing required parameter - public_id". Can you help me please??
@hotfuzz123 I made mention in my previous comment (see below) that you will need to store the public_id
as a field in your database column. you are getting that error because the $slider
object doesn't have a public_id
property. You may have to update your database table to reflect that.
@hotfuzz123 I think the only way you can do this right now is if you are storing the public_id(which could be the filename) of the uploaded file in your database. Then you can use that to delete the resource from Cloudinary by supplying the
public_id
to thedestroy()
method of the Cloudinary API.So the flow could be something like this (using the example of a user updating their profile picture):
- User enters details in the profile picture form to be updated.
- Before the actual update is done, you retrieve the
public_id
orfile_name
attached to the user in theusers
table or themedia
table which comes with the Cloudinary package.- Use the
public_id
to make adestroy
call to delete the previous image.- upload the new image to Cloudinary and update the respective tables with the new values.
Something along these lines should probably work.
I have solved my problem :))) I appreciate your help, thank you so much You should add into your documentation about:
public_id
as a field in database column.Cloudinary::destroy();
Happy to help @hotfuzz123
Just a quick tip. $slider->update($request->all())
should probably be changed to$slider->update($request->validated())
which is much safer, the former, which you are doing is dangerous and can easily let attackers inject unwanted stuff.
That said since you have been able to solve your issue, kindly close this issue. All the best.
For the getPublicId() - i have to upload it and it will get the public_id but i want to get public_id of the old image to delete it and update a new one. How can i do that - can you give me an example??