spatie / livewire-filepond

Upload files using Filepond in Livewire components
https://spatie.be/open-source
MIT License
230 stars 18 forks source link

[Bug]: Exception "Only arrays and Traversables can be unpacked" when catching event `filepond-upload-started` in PHP. #27

Open booni3 opened 1 month ago

booni3 commented 1 month ago

What happened?

#[On('filepond-upload-started')]
public function uploadStarted(): void
{
    dd('fail'); // Only arrays and Traversables can be unpacked
}

#[On('filepond-upload-finished')]
public function uploadFinished($files): void
{
    dd($files, 'ok'); // OK
}

Catching the events in Alpine works, although $event.detail only shows the model name files

<div x-data
     x-on:filepond-upload-started="console.log('started', $event.detail)"
     x-on:filepond-upload-finished="console.log('finished', $event.detail)"
>
    <x-filepond::upload wire:model="files" multiple image-preview-height="150"/>
</div>

How to reproduce the bug

-

Package Version

1.2.3

PHP Version

8.3

Laravel Version

11

Which operating systems does with happen with?

No response

Notes

No response

spacedogstudios commented 3 days ago

This error can be fixed by naming the object property in the payload. For example, the dispatch in upload.blade.php could become:

$dispatch('filepond-upload-started', { 'attribute': '{{ $wireModelAttribute }}' });

The same with the filepond-upload-reset event:

$dispatch('filepond-upload-reset', { 'attribute': '{{ $wireModelAttribute }}' });