How to Share Media Across Multiple Models Without Duplicating Files in Spatie Media Library? #3748
Unanswered
jehanzeb007
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to implement a feature where the same media file can be shared across multiple models without creating duplicate files in storage. For example I have the previous row id and I will assign to new one in db and it will be child entry but in the storage I have only one file.
Here's the functionality I am aiming for:
Assigning Media to Multiple Models:
I want to link an existing media file to different model_type and model_id entries in the database without copying the physical file. The goal is to optimize storage usage by sharing the same file across models.
Deletion Behavior:
If the media is linked to only one model, deleting the media should remove both the database record and the physical file from storage.
If the media is linked to multiple models, deleting the media should only remove the database record for that model without affecting the shared file in storage.
Storage Optimization:
I want to ensure that storage usage is minimal by keeping a single copy of the file for all linked models while maintaining proper relationships in the database.
Beta Was this translation helpful? Give feedback.
All reactions