How do I get the file in a upload action

on a resource page I have an action:

Tables\Actions\Action::make('import')
                    ->form([
                        Forms\Components\FileUpload::make('file'),
                    ])
                    ->label('')
                    ->tooltip('Import')
                    ->icon('heroicon-o-folder-open')
                    ->action('import'),


shows a modal, one can upload a file and it call my 'import' method.

But... what parameters do I get in my method?

I would lige to get the current record and then the fileupload so that I can 'import' the data in this case

public function import($record, $file)
    {

        dd($record, $file);
    }


Does not work
Solution
Here is the solution

                Tables\Actions\Action::make('import')
                    ->form([
                        FileUpload::make('file')
                            ->label('')
                            ->acceptedFileTypes(['application/json', 'json'])
                            ->imagePreviewHeight('250')
                            ->reactive()
                            ->afterStateUpdated(function (callable $set, TemporaryUploadedFile $state) {
                                $set('fileRealPath', $state->getRealPath());
                            }),
                        Hidden::make('fileRealPath'),
                    ])
                    ->label('')
                    ->tooltip('Import')
                    ->icon('heroicon-o-folder-open')
                    ->action('import'),


The trick is to store the realpath in a hidden input
Was this page helpful?