@anonymouse703 Can you show how you store the image on the create page?
Aug 8, 2024
3
Level 6
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');
}
Level 6
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),
Please or to participate in this conversation.