Aug 26, 2025
1
Level 6
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
<?php
namespace App\Models;
use App\Enums\File\Disk;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Database\Eloquent\Casts\Attribute;
class File extends Model
{
protected $fillable = [
'uploader_id',
'path',
'thumbnail_path',
'disk',
'name',
'size',
'type',
'extension',
];
/*
|--------------------------------------------------------------------------
| Attributes
|--------------------------------------------------------------------------
*/
public function fullUrl(): Attribute
{
return Attribute::make(
get: function () {
if (!in_array($this->disk, Disk::cloudDisks(true))) {
return Storage::disk($this->disk)->url($this->path);
}
if (in_array($this->disk, Disk::s3Disks(true))) {
$cloudfrontDomain = config("filesystems.disks.$this->disk.cloudfront_domain");
if (! is_null($cloudfrontDomain)) {
return $cloudfrontDomain . '/' . $this->path;
}
}
return Storage::disk($this->disk)->url($this->path);
},
);
}
public function thumbnailUrl(): Attribute
{
return Attribute::make(
get: function () {
if (is_null($this->thumbnail_path)) {
return null;
}
if (!in_array($this->disk, Disk::cloudDisks(true))) {
return Storage::disk($this->disk)->url($this->thumbnail_path);
}
if (in_array($this->disk, Disk::s3Disks(true))) {
$cloudfrontDomain = config("filesystems.disks.$this->disk.cloudfront_domain");
if (! is_null($cloudfrontDomain)) {
return $cloudfrontDomain . '/' . $this->thumbnail_path;
}
}
return Storage::disk($this->disk)->url($this->thumbnail_path);
},
);
}
}
Please or to participate in this conversation.