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β€’2y 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
ironheartkhOPβ€’2y ago
i don't want to store just return url instead if data null
toeknee
toekneeβ€’2y 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
ironheartkhOPβ€’2y ago
i mean ImageColumn in listing
toeknee
toekneeβ€’2y ago
Ahh you listed Form Builder above
ironheartkh
ironheartkhOPβ€’2y 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β€’2y 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
ironheartkhOPβ€’2y ago
using Ternary ? : i see do you mean default will handle this for us ? if data from database null
toeknee
toekneeβ€’2y 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
ironheartkhOPβ€’2y ago
thank you it's working fine
toeknee
toekneeβ€’2y ago
You are welcome
ironheartkh
ironheartkhOPβ€’2y ago
i just started with filament today and i learned a lot, thank team discord fri
toeknee
toekneeβ€’2y ago
Awesome stuff! Life just gets easier from here out! πŸ˜„
ironheartkh
ironheartkhOPβ€’2y ago
filament is my life saver lol
Dan Harrin
Dan Harrinβ€’2y ago
hang on defaultImageUrl() is a feature we added yesterday does it not work?
ironheartkh
ironheartkhOPβ€’2y ago
nope i got error 503 @toeknee_iom can i do dm to your ?
Want results from more Discord servers?
Add your server