cloudinary-community / cloudinary-laravel

Laravel SDK for Cloudinary
MIT License
259 stars 70 forks source link

detachMedia deletes ALL images attached to an entity #51

Closed ttrolololll closed 8 months ago

ttrolololll commented 2 years ago

https://github.com/cloudinary-labs/cloudinary-laravel/blob/ab0dc2d2dfefbeb67c7b282b72e6203802c36582/src/MediaAlly.php#L82

This method is problematic. It gets ALL the images associated to the entity, and deletes them all...

Need to have an if statement to check for nullness of $media param, if not null, only delete given media, else then delete all.

For a destructive action like delete all media, it should even be consider to have a separate method just for that...

Delaney commented 8 months ago

@ttrolololll the method seems to work as intended.

@unicodeveloper the method could possibly be extended to also accept a collection and delete multiple media at once

EDIT:

My bad. It does delete all files but only the specified Media model. I'd like to push a fix