-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds action to store media using spatie/laravel-medialibrary #424
base: 3.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, how are the fields like alt, etc getting saved or read from spatie's package? Since it doesn't support those as native fields on the record?
$model = $component->getContainer()->model; | ||
$media = $component->shouldPreserveFilenames() | ||
? $model->addMedia($file)->toMediaCollection('tiptap-media') | ||
: $model->addMedia($file)->usingFileName(Str::uuid())->toMediaCollection('ck-media'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is 'ck-media'?
Good points. Thank you. |
Wondering if this needs to be in the plugin itself? Seems like if could just be a Class in the app, since it can still be changed via the config. |
Well, you are the boss. But I think not. At lease no more than the "standard" way of storing files. I think adding this functionality do the core of the plugin will be beneficial taking under consideration how popular spatie/laravel-medialibrary is. |
Valid points. How would you handle inserting the converted images back into the editor? i.e, upload creates a 'medium' sized image, where would that option come to insert that size as the image in the editor. And also what if it takes a while to generate that image, you would then need a placeholder to show in the editor, which would require updates to the JS extension internally. Not totally opposed to including this, I just think there's more to it that would require some further troubleshooting, or maybe even a better implementation of something like a 'Media Provider' class or similar. |
You are right - this can be a problem as everybody can name the conversion as they see fit... The 'large' or 'medium' comes from the model. For example:
So using my spatie solution you should be able to somehow decide which conversion (if any) you want to use. I think this should be set by adding something like this (so with every model could use different conversion): TiptapEditor::make('main_text')->useSpatieConversion('large'), Or add it in setting file to use in all models. What do you think? |
Honestly, I think this is assuming a lot. But I do see the value, despite knowing, at least right now, the best way forward. Like I'm torn on supporting something I don't personally use, but at the same time it's kind of the point of being able to provide your own custom Media class. |
Purpose
By default, the media files are stored in the
public
disk in themedia
directory.This adds the possibility to store media using
spatie/laravel-medialibrary
package.The user will need to change the
media_action
key in the config filefilament-tiptap-editor.php
toSpatieMediaLibraryAction
: