© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
32 replies
Zamion101

->fill() does not work with SpatieMediaLibraryFileUpload

I am trying to implement a form where users can come back and edit their answers or upload new files but whatever I try to fill the
SpatieMediaLibraryFileUpload
SpatieMediaLibraryFileUpload
with the data fails. If I provide
uuid
uuid
,
path
path
,
url
url
it doesn't give any error but also doesn't populate the field. If I were to give
UploadedFile
UploadedFile
,
Media
Media
or
MediaCollection
MediaCollection
it gives an error with
Filament\Forms\Components\SpatieMediaLibraryFileUpload::{closure:Filament\Forms\Components\SpatieMediaLibraryFileUpload::setUp():90}(): Argument #2 ($file) must be of type string, array given
Filament\Forms\Components\SpatieMediaLibraryFileUpload::{closure:Filament\Forms\Components\SpatieMediaLibraryFileUpload::setUp():90}(): Argument #2 ($file) must be of type string, array given


this error originates from closure used in
$this->getUploadedFileUsing
$this->getUploadedFileUsing
when the function
setUp
setUp
has been called. It's driving me insane.
I have also tried to just use relationship but still the same problem!

How can I fill the field with previous data from the database?

I saw something like using
unsplash
unsplash
in the field to set the state but still didn't worked in my case.
image.png
image.png
Solution
For any one having similar problems here is the solution
1. Define your model in the
mount()
mount()
function
2. Because lazy loading is disabled for
Media
Media
model, add
->load('media')
->load('media')
to the model you are fetching
3. Explicitly define
->model($this->yourModel)
->model($this->yourModel)
in the
SpatieMediaLibraryFileUpload
SpatieMediaLibraryFileUpload

4. Fill the field using the
uuid
uuid
of the media you're trying to use

Here is the example

public function mount(Request $request, int $id): void
{
$this->participant = Participant::findOrFail($id)->load('media');

$this->form->fill([
...
'image' => $this->participant->getFirstMedia('some.collection')?->uuid
...
]);
}

...
// In your form use
SpatieMediaLibraryFileUpload::make('image')->model($this->participant);
public function mount(Request $request, int $id): void
{
$this->participant = Participant::findOrFail($id)->load('media');

$this->form->fill([
...
'image' => $this->participant->getFirstMedia('some.collection')?->uuid
...
]);
}

...
// In your form use
SpatieMediaLibraryFileUpload::make('image')->model($this->participant);


And you should be good to go.
I hope it will be helpful
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Form does not fill with data
FilamentFFilament / ❓┊help
2mo ago
SpatieMediaLibraryFileUpload doesn't work with ->multiple()
FilamentFFilament / ❓┊help
3y ago
preserveFilenames() not working with SpatieMediaLibraryFileUpload
FilamentFFilament / ❓┊help
13mo ago
SpatieMediaLibraryFileUpload not showing
FilamentFFilament / ❓┊help
3y ago