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
awcodes4w 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-webplusm4w 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
awcodes4w 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-webplusm4w ago
ok, let's try that humm, my page is extends Page
class EnterpriseProfile extends Page
class EnterpriseProfile extends Page
awcodes
awcodes4w ago
Yep. And if you track that back it extend Livewire/Component All pages in filament are livewire components.
Dan-webplusm
Dan-webplusm4w 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
awcodes4w 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-webplusm4w 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
awcodes4w 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-webplusm4w 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
awcodes4w ago
That’s why seeing the whole code helps. Glad you figured it out.