Error saving media file with spatie-laravel-media-library-plugin

Hi, I have installed the spatie-laravel-media-library-plugin plugin in my project. I've done the setup following the instructions of the plugin. However, when trying to save a image in below input I get an error which I can't seem to figure out. SpatieMediaLibraryFileUpload::make('featured_image') ->label('Featured Image') ->collection('pages') ->disk('public') ->image() ->imageEditor() Error: array_keys(): Argument #1 ($array) must be of type array, Livewire\Features\SupportFileUploads\TemporaryUploadedFile given It seems to be coming from vendor/filament/spatie-laravel-media-library-plugin/src/Forms/Components/SpatieMediaLibraryFileUpload.php:254 Does anyone had this before or maybe know whta could be the issue here? Thanks!
2 Replies
Povilas Korop
Povilas Korop3w ago
I asked ChatGPT. Haven't checked but looks like the correct answer? You’re hitting that because the component is behaving as a multi-file uploader, so Filament expects an array of files, but Livewire is giving it a single TemporaryUploadedFile. Then, inside the plugin it calls array_keys($state) and boom—$state isn’t an array. Why it happens SpatieMediaLibraryFileUpload is multiple by default (same default as FileUpload). If you want only one image, you must explicitly turn off multiple. Fix (single image)
SpatieMediaLibraryFileUpload::make('featured_image')
->label('Featured Image')
->collection('pages')
->disk('public')
->image()
->imageEditor()
->multiple(false) // <-- important
// ->maxFiles(1) // optional, but harmless with multiple(false)
SpatieMediaLibraryFileUpload::make('featured_image')
->label('Featured Image')
->collection('pages')
->disk('public')
->image()
->imageEditor()
->multiple(false) // <-- important
// ->maxFiles(1) // optional, but harmless with multiple(false)
Stijn Jansen
Stijn JansenOP3w ago
Hi @Povilas Korop Thanks! Will try it later. Seems like a possible solution👌🏽

Did you find this page helpful?