© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
2 replies
Nikunj Gadhiya

How to Set a Default Image in Laravel Filament FileUpload?

How can I set a default banner image in the file uploader?

I'm using Laravel's Filament
FileUpload
FileUpload
component, and I want to display a default banner image when the page loads. If the user uploads a new image, it should replace the default. However, if no image is uploaded, the default banner image should remain.

I've tried using the
default()
default()
method and the
formatStateUsing()
formatStateUsing()
function, but neither seems to work:

Forms\Components\FileUpload::make('banner')
    ->disk('banner')
    ->directory('banner')
    ->image()
    ->imageEditor()
    ->maxSize(3072) // 3MB limit
    ->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
    ->formatStateUsing(fn($state) => $state ?? ['banner/banner.png']) // Default banner image
    ->validationMessages([
        'banner.dimensions' => __('validationBannerDimensions'),
        'banner.max' => __('validationBannerMax'),
    ])
    ->rules([
        'dimensions:min_width=500,min_height=500,max_width=1000,max_height=1000'
    ])
    ->helperText(__('validationBannerHelperMsg')),
Forms\Components\FileUpload::make('banner')
    ->disk('banner')
    ->directory('banner')
    ->image()
    ->imageEditor()
    ->maxSize(3072) // 3MB limit
    ->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
    ->formatStateUsing(fn($state) => $state ?? ['banner/banner.png']) // Default banner image
    ->validationMessages([
        'banner.dimensions' => __('validationBannerDimensions'),
        'banner.max' => __('validationBannerMax'),
    ])
    ->rules([
        'dimensions:min_width=500,min_height=500,max_width=1000,max_height=1000'
    ])
    ->helperText(__('validationBannerHelperMsg')),


How can I correctly set the default image so that it appears when the form loads?
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

How do i set default image in FileUpload ?
FilamentFFilament / ❓┊help
17mo ago
Image Preview after $set in FileUpload field
FilamentFFilament / ❓┊help
12mo ago