F
Filament8mo ago
\

Import Action not working

Hey, I've been trying to use the import action in my application. However each time I try to upload the csv file for import I keep getting the same error. TypeError PHP 8.2.4 10.48.2 Filament\Actions\ImportAction::Filament\Actions\Concerns{closure}(): Argument #2 ($state) must be of type ?Livewire\Features\SupportFileUploads\TemporaryUploadedFile, array given, called in path\vendor\filament\support\src\Concerns\EvaluatesClosures .php on line 35 I've published all the neccessary tables as stated in the documentation and I haven't tampered with the vendor folder in any way. The problem doesn't seem to be caused by my csv file as I've tried importing my data to the filament demo where it worked perfectly. Any help would be of great help
1 Reply
\
\OP8mo ago
I've found out where the error originates from and possibly solved it. Inside the CanImportRecords trait, resposible for the actions functionality, I've modified the afterStateUpdated method on the FileUpload component (line 79) to allow the callable function to accept $state variable as an array in addition to TemporaryUploadedFile and null. Dumping the $state variable than reveals this array:1 [▼ // vendor\filament\actions\src\Concerns\CanImportRecords.php:80 "7d0f05fb-1017-4bbd-b017-5036c88bc071" => Livewire\Features\SupportFileUploads\TemporaryUploadedFile {#2265▼ /contents/ } ] The TemporaryUploadedFile object just seems to be encapsulated in the array, so I can just need to retrieve the its value. (starting at line 79)
->afterStateUpdated(function (Forms\Set $set, TemporaryUploadedFile | array | null $state) use ($action) {
if (is_array($state)) {
$state = reset($state);
}

//....
->afterStateUpdated(function (Forms\Set $set, TemporaryUploadedFile | array | null $state) use ($action) {
if (is_array($state)) {
$state = reset($state);
}

//....
I added this condition to the start I'm not sure if other people have problems with this, could do a pull request if so
Want results from more Discord servers?
Add your server