© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
3 replies
Banzai

How to use SpatieMediaLibraryFileUpload in the Builder

What I am trying to do
Using the builder my client can add blocks like "Banner/TextImage/AboutUs and so on.
For the images i want to use SpatieMediaLibrary (for the responsive images option).

The problem
When i add 1 banner, upload an image this works (the media uploads and binds to the model Page). When i add a second banner these images are both bound to the model page (changing 1 image, changes both images).

I want them to be unique to their own block in the builder (json).

What i did
In the documentation of the spatie plugin from filament: https://filamentphp.com/plugins/filament-spatie-media-library#filtering-media-2

I've got the following working

class Navigation
{
    public static function make(): Block
    {
        return Block::make('banners_navigation')
            ->label('[Banner] - Navigation')
            ->icon('heroicon-m-photo')
            ->schema([
                SpatieMediaLibraryFileUpload::make('image')
                    ->collection('image')
                    ->customProperties(fn (Get $get): array => [
                        'gallery_id' => 12345,
                    ])
                    ->filterMediaUsing(
                        fn (Collection $media): Collection => $media->where(
                            'custom_properties.gallery_id',
                            12345,
                        ),
                    ),
            ]);
    }
}
class Navigation
{
    public static function make(): Block
    {
        return Block::make('banners_navigation')
            ->label('[Banner] - Navigation')
            ->icon('heroicon-m-photo')
            ->schema([
                SpatieMediaLibraryFileUpload::make('image')
                    ->collection('image')
                    ->customProperties(fn (Get $get): array => [
                        'gallery_id' => 12345,
                    ])
                    ->filterMediaUsing(
                        fn (Collection $media): Collection => $media->where(
                            'custom_properties.gallery_id',
                            12345,
                        ),
                    ),
            ]);
    }
}


Giving the image a custom property adds

Database
Table: pages
Column: custom_properties

{
  "gallery_id": 12345
}
Database
Table: pages
Column: custom_properties

{
  "gallery_id": 12345
}


Now i am stuck how to continue or is there a better/smarter solution?
Filament
Spatie Media Library by Filament - Filament
Filament support for Spatie's Laravel Media Library package.
Spatie Media Library by Filament - Filament
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

How to use SpatieMediaLibraryFileUpload in hintAction?
FilamentFFilament / ❓┊help
3y ago
How to use storeFileNamesIn within Builder
FilamentFFilament / ❓┊help
2mo ago
How to use deep relations in filters in the V3 Table Builder?
FilamentFFilament / ❓┊help
3y ago