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

anonymouse703's avatar

How to display image in edit page?

How to display/preview image on edit page?

The case is I store all the images detail in file table for dynamic purposes.. On create preview image upon upload is ok.. the problem is on edit the image from the record is not displayed.

This is the form function in the UserResource

 public static function form(Form $form): Form
    {
        return $form
            ->schema([

                Forms\Components\FileUpload::make('photo')
                    ->image()
                    ->storeFiles(false)
                    ->avatar()
                    ->imageEditor(),
                Forms\Components\TextInput::make('name')
                    ->required()
                    ->maxLength(255),
                 Forms\Components\TextInput::make('mobile')
                ->label('Mobile Number')
                ->maxLength(15)
                ->placeholder('e.g., +639123456789')
                ->helperText('Include the country code and ensure it starts with a non-zero digit.'),

                Forms\Components\TextInput::make('email')
                    ->email()
                    ->required()
                    ->maxLength(255),
                Forms\Components\TextInput::make('password')
                    ->password()
                    ->required()
                    ->maxLength(255),
                Forms\Components\Select::make('role')
                ->options(array_combine(
                    array_map(fn($role) => $role->value, Role::cases()),
                    array_map(fn($role) => Str::title($role->value), Role::cases())
                ))
                ->required(),
            ]);
    }

Relationship

  public function photo(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(File::class, 'profile_photo_id');
    }
0 likes
3 replies
anonymouse703's avatar
anonymouse703
OP
Best Answer
Level 6

@prasadchinwal5

I just put place holder on edit to show the image

 Placeholder::make('product_image')
                ->label('Image Preview')
                ->content(fn ($record) => new HtmlString('<img src="' . ($record->photo ? url($record->photo->path) : asset('image/no-image.png')) . '"class="w-32 h-32 rounded-full" />'))
                ->visible(fn ($livewire) => $livewire instanceof \Filament\Resources\Pages\EditRecord),
jeremykes's avatar

Slightly different issue but was stuck for 2 days trying to figure out why my form was not prefilling my images. Creating records was fine but nothing showed on the edit page. There were no console errors and no laravel errors. The "D'oh!" moment came when I reverted back to all Filament FileUpload defaults and changed my .env

		APP_URL=http://localhost

to

		APP_URL=http://127.0.0.1:8000

And voilà! Everything showed up perfectly.

Hope this helps someone.

Am using Laravel 11 and Filament 3.

3 likes

Please or to participate in this conversation.