filament icon indicating copy to clipboard operation
filament copied to clipboard

Refreshing form with Action on FileUpload throws foreach() argument must be of type array|object, string given

Open MarcelWeidum opened this issue 1 year ago • 1 comments

Package

filament/filament

Package Version

v3.2.92

Laravel Version

v11.13.0

Livewire Version

v3.5.1

PHP Version

8.3.7

Problem description

I have an action button on a form. When I click it, it fetches the latest data from the database and should update in the form with $livewire->refreshFormData.

Every other field works but the FileUpload throw the error: foreach() argument must be of type array|object, string given.

My action:

Section::make('Section')
    ->headerActions([
        Action::make('refresh')
            ->icon('heroicon-o-arrow-path')
            ->color('warning')
            ->size(ActionSize::Small)
            ->hidden(fn ($record) => !$record)
            ->requiresConfirmation()
            ->action(function($record, $livewire) {
                $record = $record->fresh();

                $livewire->refreshFormData(['name', 'image']);

                Notification::make()
                    ->title('Refreshed data')
                    ->success()
                    ->send();
            }),
    ])

I also tried setting $record->image = [$record->image] before refreshFormData.

Expected behavior

Also refreshing the FileUpload field.

Steps to reproduce

  1. Clone the reproduction repository and make a filament user
  2. Create a customer
  3. Edit the customer
  4. Click the refresh action button on the edit page

Reproduction repository (issue will be closed if this is not valid)

https://github.com/MarcelWeidum/filament-refresh-fileupload-bug

Relevant log output

foreach() argument must be of type array|object, string given

Donate 💰 to fund this issue

  • You can donate funding to this issue. We receive the money once the issue is completed & confirmed by you.
  • 100% of the funding will be distributed between the Filament core team to run all aspects of the project.
  • Thank you in advance for helping us make maintenance sustainable!
Fund with Polar

MarcelWeidum avatar Jul 14 '24 18:07 MarcelWeidum

->action(function($record, $livewire) {
    $record = $record->fresh();
    $record->image = [(string) Str::uuid() => $record->image];

    $livewire->record = $record;
    $livewire->refreshFormData(['name', 'image']);

    Notification::make()
        ->title('Refreshed data')
        ->success()
        ->send();
}),

awcodes avatar Jul 18 '24 17:07 awcodes