How to clearMediaCollection without deleting files? #2743
Unanswered
johncarter-
asked this question in
Q&A
Replies: 2 comments
-
Try |
Beta Was this translation helpful? Give feedback.
0 replies
-
A better solution is to call the https://spatie.be/docs/laravel-medialibrary/v9/basic-usage/retrieving-media |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I have a situation with user profile photos, where I want the user to be able to remove the profile from their account, but I don't want to delete it because there will be historic references to that path (e.g. old database notifications).
I thought I could do something like this:
$this->user->media('profiles')->each(fn (Media $media) => $media->model()->dissociate()->save());
For this to work, however, I would need to publish and modify the default migration to make the
model_type
andmodel_id
nullable which seems acceptable.I just wanted to know if any one has a better way of removing media from a collection without actually deleting the file?
Beta Was this translation helpful? Give feedback.
All reactions