FileUpload on a custom page won't work as expect ...

I'm trying to save just one image , but that save in an array; Don't know why. Trying to save that manually and it's always failed. So does that FileUpload work on a custom page ? If yes, let me know how ...
11 Replies
awcodes
awcodes6mo ago
What codes have you tried? And yes FileUpload works in custom page but it still has to be part of a filament form.
Dan-webplusm
Dan-webplusmOP6mo ago
Just same as the doc
Forms\Components\FileUpload::make('attachment')
->disk('public')
->directory('logos')
->acceptedFileTypes(['image/png', 'image/webp', 'image/svg+xml']),

// in my save method
$path = $file->store('logos','public');
Forms\Components\FileUpload::make('attachment')
->disk('public')
->directory('logos')
->acceptedFileTypes(['image/png', 'image/webp', 'image/svg+xml']),

// in my save method
$path = $file->store('logos','public');
i try, minFiles, etc ... and same when delete the file, nothing happen lol
awcodes
awcodes6mo ago
Ok. Well the custom page is just a raw livewire component so you need to follow all the steps in adding a form to a livewire component. https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component
Dan-webplusm
Dan-webplusmOP6mo ago
ok, let's try that humm, my page is extends Page
class EnterpriseProfile extends Page
class EnterpriseProfile extends Page
awcodes
awcodes6mo ago
Yep. And if you track that back it extend Livewire/Component All pages in filament are livewire components.
Dan-webplusm
Dan-webplusmOP6mo ago
yes, i knew it. It 's why i tell to show me if you have an exemple of that. this look like a bug in page
awcodes
awcodes6mo ago
There’s no bug in page. Did you add $this->form->fill() in the mount method? I need to see whole code to help more. Just showing the FileUpload doesn’t help much.
Dan-webplusm
Dan-webplusmOP6mo ago
yes, it 's just for an update page form. all work very well, since i decided to add the uploadField manually, it's save. but if i try to remove that image, it's remove only on the component, not the file. Maybe i need to did it myself ?
awcodes
awcodes6mo ago
Yea. Removing the file in the form only removes it from the record. It’s not going to actually delete the file in storage. You would need an observer or delete it manually during the save process.
Dan-webplusm
Dan-webplusmOP6mo ago
Thank fully for your timeshare 👍 O_O , i saw my mistake on updating , just need to update the data with $this->form->getState(), not $this->data. Oh my bad ...
awcodes
awcodes6mo ago
That’s why seeing the whole code helps. Glad you figured it out.
Want results from more Discord servers?
Add your server