Skip to content
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

Handle file uploads directly in Presentation resources, via the content field #1

Open
alkrauss48 opened this issue Feb 16, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@alkrauss48
Copy link
Owner

alkrauss48 commented Feb 16, 2024

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:

  1. Get the current model to associate the images to. $this->getRecord() doesn't work.
  2. Figure out how to handle images for new not-yet-created records. I.e. Can we even attach an image to a new record?
  3. 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.
@alkrauss48 alkrauss48 added the enhancement New feature or request label Feb 16, 2024
@alkrauss48 alkrauss48 self-assigned this Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant