F
Filamentβ€’2y ago
Matthew

Changing the disk when you upload attachment in RichEditor

public static function form(Form $form): Form
{
return $form
->schema([
Card::make([
Forms\Components\TextInput::make('title')
->required()
->columnSpan(2)
->maxLength(255),
Forms\Components\RichEditor::make('content')
->columnSpan(2)
->required(),
]),
Card::make([
Forms\Components\Select::make('author_id')
->options([Auth()->id() => Auth()->user()->name])
->default(Auth()->id())
->disabled(),
Forms\Components\DatePicker::make('released_at'),
])->columns(2)
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Card::make([
Forms\Components\TextInput::make('title')
->required()
->columnSpan(2)
->maxLength(255),
Forms\Components\RichEditor::make('content')
->columnSpan(2)
->required(),
]),
Card::make([
Forms\Components\Select::make('author_id')
->options([Auth()->id() => Auth()->user()->name])
->default(Auth()->id())
->disabled(),
Forms\Components\DatePicker::make('released_at'),
])->columns(2)
]);
}
Is it possible to somehow tell filament where to store an attachment when you upload something in the RichEditor?
10 Replies
toeknee
toekneeβ€’2y ago
Please do try to read the docs πŸ˜‰ RichEditor::make('content') ->fileAttachmentsDisk('s3') ->fileAttachmentsDirectory('attachments') ->fileAttachmentsVisibility('private') https://filamentphp.com/docs/2.x/forms/fields#rich-editor
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Matthew
MatthewOPβ€’2y ago
Ah sorry. I missed it πŸ˜…
Matthew
MatthewOPβ€’2y ago
Ok so I decided to use FileUpload for attachment.
public static function form(Form $form): Form
{
return $form
->schema([
Card::make([
Forms\Components\TextInput::make('title')
->required()
->columnSpan(2)
->maxLength(255),
Forms\Components\RichEditor::make('content')
->columnSpan(2)
// ->fileAttachmentsDisk('secured_disk')
->disableToolbarButtons([
'attachFiles',
])
->required(),
FileUpload::make('attachment')
->required()
->multiple()
->columnSpan(2)
->enableOpen()
->disk('secured_disk')
->visibility('private')
// ->storeFileNamesIn('attachment_file_names')
->enableDownload()
->maxSize(25600)
]),
Card::make([
Forms\Components\Select::make('author_id')
->options([Auth()->id() => Auth()->user()->name])
->default(Auth()->id())
->disabled(),
Forms\Components\DatePicker::make('released_at'),
])->columns(2)
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Card::make([
Forms\Components\TextInput::make('title')
->required()
->columnSpan(2)
->maxLength(255),
Forms\Components\RichEditor::make('content')
->columnSpan(2)
// ->fileAttachmentsDisk('secured_disk')
->disableToolbarButtons([
'attachFiles',
])
->required(),
FileUpload::make('attachment')
->required()
->multiple()
->columnSpan(2)
->enableOpen()
->disk('secured_disk')
->visibility('private')
// ->storeFileNamesIn('attachment_file_names')
->enableDownload()
->maxSize(25600)
]),
Card::make([
Forms\Components\Select::make('author_id')
->options([Auth()->id() => Auth()->user()->name])
->default(Auth()->id())
->disabled(),
Forms\Components\DatePicker::make('released_at'),
])->columns(2)
]);
}
But I the attachment doesnt load in the edit page. What could be the issue? This is the secure disk that I made:
'secured_files' => [
'driver' => 'local',
'root' => storage_path('app/secured_files'), // The path to your secured files directory
'url' => env('APP_URL').'/secured_storage',
'visibility' => 'public',
'throw' => false,
],
'secured_files' => [
'driver' => 'local',
'root' => storage_path('app/secured_files'), // The path to your secured files directory
'url' => env('APP_URL').'/secured_storage',
'visibility' => 'public',
'throw' => false,
],
toeknee
toekneeβ€’2y ago
Visibility private?
Matthew
MatthewOPβ€’2y ago
even if you have it "public", it still doesnt work I can see the file being stored
toeknee
toekneeβ€’2y ago
Can you access the file Via URL Fairly sure public/private only works for s3
Matthew
MatthewOPβ€’2y ago
No I cannot
toeknee
toekneeβ€’2y ago
There is your problem, it’s not a filament issue
Matthew
MatthewOPβ€’2y ago
Maybe its an issue in the way ive structured the disk?
awcodes
awcodesβ€’2y ago
When you run storage:link Laravel only links to the public directory. If you want to have disks outside of that you’ll have to register them manually with the filesystems config. https://laravel.com/docs/10.x/filesystem#the-public-disk
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation β€” freeing you to create without sweating the small things.
Want results from more Discord servers?
Add your server