Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

myregistration's avatar

How do you customize the dislplay for Filament SpatieMediaLibraryFileUpload field?

I'm using Filament's SpatieMediaLibraryFileUpload field set to multiple and it displays them one on top of each other and in the reverse column order. Anyone know how to customize the display? Have you noticed the order is reversed? So if you drag the image to top and save you are actually saving as order_column=3 and when it's displayed by filament it lists the image at the top, but if you use limit 1 to display the image in a SpatieMediaLibraryImageColumn table column it will display the image that is actually order_column=1. What's going on? It seems like the list of images for SpatieMediaLibraryFileUpload are displaying in reverse? How can I fix that? Here's an example

Filament Form:

SpatieMediaLibraryFileUpload::make('images')
                        ->label('Images')
                        ->collection('images')
                        ->multiple()
                        ->reorderable()

Filament Table:

 SpatieMediaLibraryImageColumn::make('image')
                    ->collection('images')
                    ->limit(1)

Do I need to pass CSS? Publish and customize Spatie's vendor files? Reference a blade view? Any advice appreciate. Thanks!

P.S. How can I include an image in the markdown? I tried a couple suggestions, but it didn't work.

0 likes
3 replies
LaryAI's avatar
Level 58

To customize the display of the SpatieMediaLibraryFileUpload field in Filament, you can indeed use CSS to style the elements as you wish. You can also override the default views if you need more control over the HTML structure.

Here's how you can approach each method:

1. Custom CSS:

You can add custom CSS to your Filament admin panel by publishing the Filament config file and adding your custom stylesheets.

First, publish the Filament config file if you haven't already:

php artisan vendor:publish --tag=filament-config

Then, add your custom CSS file path to the stylesheets array in the config/filament.php file:

'stylesheets' => [
    // Your existing stylesheets...
    '/css/custom-filament.css', // Path to your custom CSS file
],

In your public/css/custom-filament.css file, you can add styles to target the media library upload field. For example:

/* Reverse the order of the images */
.filament-media-library-file-upload-preview-list {
    display: flex;
    flex-direction: column-reverse;
}

/* Custom styles for the images */
.filament-media-library-file-upload-preview-card {
    /* Your custom styles here */
}

2. Overriding Views:

If you need to change the HTML structure, you can publish the views of the Spatie Media Library package and customize them.

First, publish the views:

php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="views"

Then, locate the published views in the resources/views/vendor/media-library directory and modify them as needed.

3. Reference a Blade View:

If you want to use a custom Blade view for the display of the media items, you can create a custom component and reference it in your Filament resource.

Create a Blade component, for example, resources/views/components/custom-media-item.blade.php, and then use it in your Filament resource like so:

SpatieMediaLibraryFileUpload::make('images')
    ->label('Images')
    ->collection('images')
    ->multiple()
    ->reorderable()
    ->view('components.custom-media-item') // Reference your custom Blade view

In your custom Blade view, you can loop through the media items and display them as you wish.

Including an Image in Markdown:

To include an image in markdown, you can use the following syntax:

![Alt text](/path/to/image.jpg "Optional title")

Make sure the path to the image is correct and accessible from where the markdown is being rendered.

Remember to clear your cache and recompile your assets if necessary after making changes to CSS or views:

php artisan optimize:clear
npm run dev // or npm run prod for production

By using one of these methods, you should be able to customize the display of the SpatieMediaLibraryFileUpload field to your liking.

Wessam-Abozeid's avatar

"php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="views""

returns 'No publishable resources for tag'. Anyone knows why?

Please or to participate in this conversation.