© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago
kippie1985

Preload/Persist Spatie Media Library Field

Hi all,

A client of us reported a "bug" in our system. They can create products in the CMS and upload images to this product. We use the excellent Filament Spatie Media Library plugin for this. They have the possibility to save a draft of a new product so they can finalize it later when all the product details are known.

What we do when they save the draft, is create a Draft model (id (int 11), model (var 255), data (json)) with all the currently known details such as title, description etc. We do this using the Filament\Forms\Get $get method. So $get('title'), $get('description'), we put those values in an array and json_encode this.

The "bug" we're experiencing right now is that when they have uploaded some images, these are serialized (livewire-file:G1tFQf7LWMashwWzEhTtu1BvuRX4ag-metadGVzdGJlZWxkLmpwZWc=-.jpg) and saved. We serialize them using:

$data['images'] = collect($get('images'))->mapWithKeys(function ($images, $key) {
    return [$key => collect($images)->map(function ($image) {
        return $image instanceof TemporaryUploadedFile ? $image->serializeForLivewireResponse() : $image;
    })->toArray()];
})->toArray();
$data['images'] = collect($get('images'))->mapWithKeys(function ($images, $key) {
    return [$key => collect($images)->map(function ($image) {
        return $image instanceof TemporaryUploadedFile ? $image->serializeForLivewireResponse() : $image;
    })->toArray()];
})->toArray();


After fetching the draft again, we unserialize the images, so that they are transformed to a Livewire\Features\SupportFileUploads\TemporaryUploadedFile (See screenshot). This looks all good, but my upload fields stay empty. Does someone here know how to solve this?
Screenshot_2024-04-17_at_15.05.20.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Spatie Media Library
FilamentFFilament / ❓┊help
10mo ago
Spatie Media Library
FilamentFFilament / ❓┊help
14mo ago
Builder blocks with spatie media library field
FilamentFFilament / ❓┊help
3y ago
filament-spatie-media-library
FilamentFFilament / ❓┊help
15mo ago