The Filament MarkdownEditor natively supports file uploads and drag-and-drop, as well as handling file visibility/disk/etc.
However, Simple Slides limits users to a certain file space used, and thus we need to use Laravel-medialibrary to track that information, which is different from what the MarkdownEditor natively uses (It just uses Laravel's store
or storePublicly
functions, which only upload the file and don't add any database records).
Currently, until this issue is addressed, we are disabling file uploads directly on a presentation record via the content field. This is limiting, because it makes sense to have presentation-specific file uploads, instead of requiring all images to be uploaded to the global ImageLibrary.
We can start to get the behavior that we want by using a couple methods that the MarkdownEditor
component provides: saveUploadedFileAttachmentsUsing
and getUploadedAttachmentUrlUsing
. Here is an example:
use Filament\Forms\Components\MarkdownEditor;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
MarkdownEditor::make('content')
])->saveUploadedFileAttachmentsUsing(function(TemporaryUploadedFile $file) : Media {
$record = $this->getRecord();
return $record->addMedia($attachment)->toMediaCollection('images');
})->getUploadedAttachmentUrlUsing(function(Media $file) : string {
return $file->getUrl();
}),
However, there are some issues with this, hence this issue:
What Needs Done
Based on the code example above, we need to:
- Get the current model to associate the images to.
$this->getRecord()
doesn't work.
- Figure out how to handle images for new not-yet-created records. I.e. Can we even attach an image to a new record?
- If enabling this feature, then we need a way for users to delete these images too, since they count towards their allotted space. This could potentially be done via a RelationManager for
Media
records (which would include the thumbnail), but it would make the workflow a bit more complex than normal.