filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.38k stars 2.72k forks source link

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

Open MarcelWeidum opened 1 month ago

MarcelWeidum commented 1 month ago

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

Fund with Polar

awcodes commented 1 month ago
->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();
}),