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

anonymouse703's avatar

how to display the image on edit in FileUpload?

On edit the image will display the old/stored image. This is working on the Filament v3 but on the v4 it's not working

EditProduct page

protected function mutateFormDataBeforeFill(array $data): array
    {
        $record = $this->getRecord();

        /**
         * @var File $file
         * @var Product $record
         */
        if ($file = $record->productImage) {
            $data['photo'] = [
                'disk' => $file->disk,
                'path' => $file->path
            ];
        }
        return $data;
    }

Form

FileUpload::make('photo')
                    ->image()
                    ->label(fn ($context) => $context === 'edit' ? 'Update Profile Photo' : 'Upload Profile Photo')
                    ->storeFiles(false)
                    ->moveFiles()
                    ->imageEditor(),

Product

  public function productImage() : BelongsTo
    {
        return $this->belongsTo(File::class, 'product_photo_id');
    }

and the File

0 likes
1 reply

Please or to participate in this conversation.