How do I upload file on click only?
public $import_file = null;
protected function getFormSchema(): array
{
return [
Section::make('Import User Instructions')
->description('Instructions for importing users into the system')
->schema([
\Filament\Forms\Components\View::make('partials.import-instructions'),
FileUpload::make('import_file')
->label('Import File')
->acceptedFileTypes(['text/csv', 'application/vnd.ms-excel'])
->helperText('Upload an Excel (.CSV) file with the required user data.'),
])
->compact()
->collapsible()
->footerActions([
Actions\Action::make('importUsers')
->label('Import Users')
->button()
->color('success')
->action(fn() => $this->importUsers()),
])
->footerActionsAlignment(Alignment::End),
];
}
public function importUsers(): void
{
$this->validate([
'import_file' => 'required|file|max:2048',
], [
'import_file.required' => 'Please upload a file.',
]);
Import::start(
file: $this->import_file
);
Notification::make()
->title('File Uploaded')
->success()
->send();
}public $import_file = null;
protected function getFormSchema(): array
{
return [
Section::make('Import User Instructions')
->description('Instructions for importing users into the system')
->schema([
\Filament\Forms\Components\View::make('partials.import-instructions'),
FileUpload::make('import_file')
->label('Import File')
->acceptedFileTypes(['text/csv', 'application/vnd.ms-excel'])
->helperText('Upload an Excel (.CSV) file with the required user data.'),
])
->compact()
->collapsible()
->footerActions([
Actions\Action::make('importUsers')
->label('Import Users')
->button()
->color('success')
->action(fn() => $this->importUsers()),
])
->footerActionsAlignment(Alignment::End),
];
}
public function importUsers(): void
{
$this->validate([
'import_file' => 'required|file|max:2048',
], [
'import_file.required' => 'Please upload a file.',
]);
Import::start(
file: $this->import_file
);
Notification::make()
->title('File Uploaded')
->success()
->send();
}I am trying to upload a file however I get this error and do not know what to do next.
