FilamentF
Filament•2y ago
NDO

ImageColumn default url for stacked columns

Hey đź‘‹ I am trying to create a stacked image column for related model (users). Because user model image is not required I want to set default image url with method that returns full url of user avatar if his img_path field is empty.

I tried with code below but it is not working because the method defaultImageUrl should return the string and not the array value. Does anyone know how I can set default image url for the stacked ImageColumn?

Tables\Columns\ImageColumn::make('users.img_path')
->label('Peoples')
->circular()
->stacked()
->limit()
->limitedRemainingText()
->defaultImageUrl(function ($record) {
$images=[];
foreach($record->users as $user) {
$images[] = $user->getImageUrl();
}
return $images;
}),
Solution
I think this would be better as an attribute on the model that can return the default image if it doesn’t exist. Then reference that attribute for the column instead of img_path. Then you don’t need to worry about the defaultImageUrl.
Was this page helpful?