F
Filament14mo ago
MRBUG

Get Name Of Table Column?

I think this is used to get data on the Table Column. From documentation
use Filament\Tables\Columns\TextColumn;

TextColumn::make('title')
->description(fn (Post $record): string => $record->description)
use Filament\Tables\Columns\TextColumn;

TextColumn::make('title')
->description(fn (Post $record): string => $record->description)
But i want little bit diffrent functionallity this is the code
Tables\Columns\ImageColumn::make('profile_photo')
->circular()->label('')->extraImgAttributes(['loading' => 'lazy'])->height(30)**->defaultImageUrl(url('https://ui-avatars.com/api/?name=' . 'full' . '&color=ffffff&background=5a51ec'))**,
Tables\Columns\TextColumn::make('name')
->numeric()
->sortable()->searchable(),
Tables\Columns\ImageColumn::make('profile_photo')
->circular()->label('')->extraImgAttributes(['loading' => 'lazy'])->height(30)**->defaultImageUrl(url('https://ui-avatars.com/api/?name=' . 'full' . '&color=ffffff&background=5a51ec'))**,
Tables\Columns\TextColumn::make('name')
->numeric()
->sortable()->searchable(),
Where i have name of user and Profile photo field so i want that if user has no profile photo he will get defaultImageUrl
->defaultImageUrl(url('https://ui-avatars.com/api/?name=' . ' USER NAME' . '&color=ffffff&background=5a51ec'))
->defaultImageUrl(url('https://ui-avatars.com/api/?name=' . ' USER NAME' . '&color=ffffff&background=5a51ec'))
and i want the name of user insted of USER NAME How can i get user name there thank you in advance ❤️.
Solution:
Like this?
->defaultImageUrl(fn (User $record) => 'https://ui-avatars.com/api/?name=' . $user->name. '&color=ffffff&background=5a51ec')
->defaultImageUrl(fn (User $record) => 'https://ui-avatars.com/api/?name=' . $user->name. '&color=ffffff&background=5a51ec')
...
Jump to solution
6 Replies
Solution
ZedoX
ZedoX14mo ago
Like this?
->defaultImageUrl(fn (User $record) => 'https://ui-avatars.com/api/?name=' . $user->name. '&color=ffffff&background=5a51ec')
->defaultImageUrl(fn (User $record) => 'https://ui-avatars.com/api/?name=' . $user->name. '&color=ffffff&background=5a51ec')
MRBUG
MRBUGOP14mo ago
i tried this but it is saying there is one correction $record->name thank you so much you are so fast @ZedoX thanks alot
DrByte
DrByte14mo ago
Alternative: Or maybe just use default Laravel attribute getter to generate the avatar if no image is stored to the record.
ZedoX
ZedoX14mo ago
I'd do the same, so i can rest assured no matter where i call the "$user->profile_photo_url", i'd get a url
MRBUG
MRBUGOP14mo ago
that's impressive thanks
ZedoX
ZedoX14mo ago
and not worry about setting a fallback default in every place
Want results from more Discord servers?
Add your server