How to get file in action form

Hi, i have this modal form on list page and i need to get file in submit method, but i do not know how, is it possible? under data is just string with file name that not exists.
class ListPayments extends ListRecords
{
protected static string $resource = PaymentResource::class;

protected function getHeaderActions(): array
{
return [
Actions\Action::make('create')
->label('Import')
->action(function (array $data) {
$this->save($data);
})
->modalHeading('Import payments')
->form([
Select::make('type')
->options([
'raiffeisenbank' => 'Raiffeisenbank CSV Payment export',
'default' => 'Default system export',
])
->required(),
FileUpload::make('file')
->acceptedFileTypes(['text/csv', 'text/plain'])
->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file) {
return (string) Str::uuid() . '.' . $file->getClientOriginalExtension();
})
->required()
->helperText('Imported payments will be pared with current records and edited or create new records'),
])
->modalButton('Import')
];
}

public function save(array $data)
{
$file = $data['file'];

dd($file);
}
}
class ListPayments extends ListRecords
{
protected static string $resource = PaymentResource::class;

protected function getHeaderActions(): array
{
return [
Actions\Action::make('create')
->label('Import')
->action(function (array $data) {
$this->save($data);
})
->modalHeading('Import payments')
->form([
Select::make('type')
->options([
'raiffeisenbank' => 'Raiffeisenbank CSV Payment export',
'default' => 'Default system export',
])
->required(),
FileUpload::make('file')
->acceptedFileTypes(['text/csv', 'text/plain'])
->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file) {
return (string) Str::uuid() . '.' . $file->getClientOriginalExtension();
})
->required()
->helperText('Imported payments will be pared with current records and edited or create new records'),
])
->modalButton('Import')
];
}

public function save(array $data)
{
$file = $data['file'];

dd($file);
}
}
Thanks for any help
1 Reply
LeandroFerreira
LeandroFerreira4mo ago
You can use the Storage facade https://laravel.com/docs/11.x/filesystem#retrieving-files
->action(function (array $data) {
$file = Storage::disk('public')->get($data['file']);
})
->action(function (array $data) {
$file = Storage::disk('public')->get($data['file']);
})
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