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(),


When I dump data I can see 'favicon' field with correct image path but preview is not working on file upload component.
Was this page helpful?