© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
Darpan

How to set existing image to file upload field?

I am trying to fetch favicon from url and update file upload field with fetched icon but preview is not working.

TextInput::make('url')->lazy()
->afterStateUpdated(function (Closure $set, $state) {
   $domain = UrlHelper::getDomain($state);
   $faviconName = str($domain)->replace('.', '-');
   $faviconPath = public_path('images/favicons/' . $faviconName . '.png');
     try {
       $ic = Image::make('https://api.faviconkit.com/' . $domain . '/16')
         ->encode('png')
         ->resize(16, 16)
         ->save($faviconPath);
       $ic->destroy();
     } catch (Exception) {
       copy(public_path('images/default-favicon.png'), $faviconPath);
     }

     // How to do this?
     $set('favicon', [$faviconPath]);
   }),

 FileUpload::make('favicon')->image(),
TextInput::make('url')->lazy()
->afterStateUpdated(function (Closure $set, $state) {
   $domain = UrlHelper::getDomain($state);
   $faviconName = str($domain)->replace('.', '-');
   $faviconPath = public_path('images/favicons/' . $faviconName . '.png');
     try {
       $ic = Image::make('https://api.faviconkit.com/' . $domain . '/16')
         ->encode('png')
         ->resize(16, 16)
         ->save($faviconPath);
       $ic->destroy();
     } catch (Exception) {
       copy(public_path('images/default-favicon.png'), $faviconPath);
     }

     // How to do this?
     $set('favicon', [$faviconPath]);
   }),

 FileUpload::make('favicon')->image(),


When I dump data I can see 'favicon' field with correct image path but preview is not working on file upload component.
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

Set image to custom field
FilamentFFilament / ❓┊help
3y ago
Multiple Image file Upload
FilamentFFilament / ❓┊help
3y ago
Simple file upload field
FilamentFFilament / ❓┊help
3y ago
How to hide placeholder of file upload field?
FilamentFFilament / ❓┊help
2y ago