How do i set default image in FileUpload ?

How do I set the default image in the fileupload form component? or can i show the default image while file upload ?
<?php
Forms\Components\FileUpload::make('company_logo')
->label('Company Logo')
->image()
->required()
->rules([
'image',
'mimes:jpeg,png,jpg',
'max:2048',
'dimensions:max_width=300,max_height=200',
])
->default(fn ($record) => $record && $record->company_logo ? $record->company_logo : asset('/images/company_logo.png')
->disk('company_logo') // from filesystems.php
->maxFiles(1)

?>
<?php
Forms\Components\FileUpload::make('company_logo')
->label('Company Logo')
->image()
->required()
->rules([
'image',
'mimes:jpeg,png,jpg',
'max:2048',
'dimensions:max_width=300,max_height=200',
])
->default(fn ($record) => $record && $record->company_logo ? $record->company_logo : asset('/images/company_logo.png')
->disk('company_logo') // from filesystems.php
->maxFiles(1)

?>
I have also try
<?php
->defaultImageUrl(asset('/images/company_logo.png'))
?>
<?php
->defaultImageUrl(asset('/images/company_logo.png'))
?>
3 Replies
Ali
Ali2mo ago
heyo did you find a solution
toeknee
toeknee2mo ago
try:
Forms\Components\FileUpload::make('company_logo')
->label('Company Logo')
->image()
->required()
->rules([
'image',
'mimes:jpeg,png,jpg',
'max:2048',
'dimensions:max_width=300,max_height=200',
])
->formatStateUsing(fn ($record) => $record?->company_logo ?? asset('/images/company_logo.png'))
->disk('company_logo') // from filesystems.php
->maxFiles(1)
Forms\Components\FileUpload::make('company_logo')
->label('Company Logo')
->image()
->required()
->rules([
'image',
'mimes:jpeg,png,jpg',
'max:2048',
'dimensions:max_width=300,max_height=200',
])
->formatStateUsing(fn ($record) => $record?->company_logo ?? asset('/images/company_logo.png'))
->disk('company_logo') // from filesystems.php
->maxFiles(1)
Ali
Ali2mo ago
heyo thanks for the reply,i have put it in a different thread https://discord.com/channels/883083792112300104/1302665182996070440
Want results from more Discord servers?
Add your server