The main difference is that one is a many to many association on the media to model (Laravel Mediable) and the other is a one to many (Spatie Media Library).
I'm looking at user uploads, if the same image is uploaded many times, with Spatie Media Library, the image will also be duplicated on the server many times.
But with Laravel Mediable the image is only uploaded once, and can be associated with many models.
This seems like an obvious win but the Spatie Media Library seems easy to use from a development perspective.
Which would you use? Or do you use for your projects?
if the user uploads an image and you want to try and use a previous instance you have to do extra work to try and compare the new image against all existing images to see if it is the same.
Alternatively you present all existing images to the user to allow them to choose one
If you have used wordpress you will understand this behaviour as per their media library.
At the end of the day it depends on your application as to whether its a benefit to the user to select previous images rather than re-upload. No one else can tell you if this is a benefit to your users.
@Snapey the user does not select an image, they just upload whatever they want. The image they upload may exist or not exist in the sites library. For example, a picture of the user would not exist, but a popular meme would (as it had already been uploaded by another user).
I was planning to hash the image contents then store this in the database, then when any user uploads an image, the hash is checked via the database, if the hash exists just return the reference, if it does not exist, upload the image and return the reference.
@panthro it might reduce the storage costs if storage cost is an issue. Is it an issue? Or might be an issue at some point in the far future? (premature optimisation)
@panthro Did you ever come to a conclusion on this?
In a similar position really that Spatie's features are amazing, yet, not being able to customise certain things or (as you say) have a many to many relationship is pretty limiting. Something like this would reduce a lot of time for me but certain setups in a product we have mean we can't realistically go down this route as the migration time would be monumental.
So would be interested in what conclusion you came to?