ahmedkandel / nova-s3-multipart-upload

A Laravel Nova resource tool to upload files directly to Amazon S3. You can (upload | download | delete) single, multiple, small or big files.
MIT License
22 stars 22 forks source link

Spatie media library compatability? #7

Closed bryanjamesmiller closed 3 years ago

bryanjamesmiller commented 3 years ago

Thanks again for the great library!

Perhaps I am mistaken, but your package currently not compatible with the Spatie Media library? The Spatie Media library uses MorphMany relationship - any chance of implementing a connection there?

ahmedkandel commented 3 years ago

Thanks Bryan, I'm not aware of any direct incompatibility with MorphMany relationship as the child models get created the same way like HasMany.

Maybe your issue with Spatie Media Liberary is that the media() MorphMany relationship needs other data to be passed to create method to fulfill the DB table requirements https://github.com/spatie/laravel-medialibrary/blob/master/database/migrations/create_media_table.php.stub

Can you explain more what kind of error you get? And how is your implementation?

bryanjamesmiller commented 3 years ago

Thanks for the quick responses. It turns out we can just rip out the Spatie Media Library, as at this point it adds an unnecessary layer in our app. It may work as you suggest, I didn't even try it because I didn't see MorphMany listed in the docs as an available option, so I assumed it was not supported. I'm glad to see it might be possible though - you may want to add MorphMany to the docs! Thanks again!

jakecausier commented 3 years ago

If anyone is interested in implementing this themselves (I'm using it mainly to use Spatie's conversions), you can do the following:

  1. Use Spatie's Media model/table, and create a separate model/table such as Photos or TempMedia
  2. Connect this tool to your temp model using the hasOne or hasMany method with any disk you want
  3. Set up an observer to watch for when a temp model is created, use an event or job to pass it to Spatie's addMediaFromDisk function with the disk you used
  4. Delete the temp model entry afterwards