F
Filamentβ€’14mo ago
ironheartkh

How can i change imagecolumn if null and return url instead of url from database?

How can i change imagecolumn if null and return url instead of url from database?
16 Replies
toeknee
toekneeβ€’14mo ago
Do you really want to store a default url when it is null? why not just render the default image if it's null?
ironheartkh
ironheartkhβ€’14mo ago
i don't want to store just return url instead if data null
toeknee
toekneeβ€’14mo ago
But you are using a form, so if you are returning a url you will be saving that url when it's returned?
ironheartkh
ironheartkhβ€’14mo ago
i mean ImageColumn in listing
toeknee
toekneeβ€’14mo ago
Ahh you listed Form Builder above
ironheartkh
ironheartkhβ€’14mo ago
Tables Columns Tables\Columns\ImageColumn::make('profile_pic')->label('Profile Picture'), i need something like this $image = true image ? Tables\Columns\ImageColumn::make('profile_pic') : Tables\Columns\ImageColumn::make('profile_pic')->defaultImageUrl(url('/images/placeholder.png'))
toeknee
toekneeβ€’14mo ago
ImageColumn::make('profile_photo_path')->circular()->label('Avatar')->default('https://ui-avatars.com/api/?name={first_name}+{last_name}&color=7F9CF5&background=EBF4FF'),
ImageColumn::make('profile_photo_path')->circular()->label('Avatar')->default('https://ui-avatars.com/api/?name={first_name}+{last_name}&color=7F9CF5&background=EBF4FF'),
ironheartkh
ironheartkhβ€’14mo ago
using Ternary ? : i see do you mean default will handle this for us ? if data from database null
toeknee
toekneeβ€’14mo ago
Good example is this working:
ImageColumn::make('profile_photo_path')->circular()->label('Avatar')->default(fn ($record) => 'https://ui-avatars.com/api/?name='.$record->first_name.'+'.$record->last_name.'&color=7F9CF5&background=EBF4FF'),
ImageColumn::make('profile_photo_path')->circular()->label('Avatar')->default(fn ($record) => 'https://ui-avatars.com/api/?name='.$record->first_name.'+'.$record->last_name.'&color=7F9CF5&background=EBF4FF'),
yes it will, as if it is empty a default is applied
ironheartkh
ironheartkhβ€’14mo ago
thank you it's working fine
toeknee
toekneeβ€’14mo ago
You are welcome
ironheartkh
ironheartkhβ€’14mo ago
i just started with filament today and i learned a lot, thank team discord fri
toeknee
toekneeβ€’14mo ago
Awesome stuff! Life just gets easier from here out! πŸ˜„
ironheartkh
ironheartkhβ€’14mo ago
filament is my life saver lol
Dan Harrin
Dan Harrinβ€’14mo ago
hang on defaultImageUrl() is a feature we added yesterday does it not work?
ironheartkh
ironheartkhβ€’14mo ago
nope i got error 503 @toeknee_iom can i do dm to your ?