ImageColumn and multiple avatars

shouldnt ImageColumn::make('belongsToManyRelationship.avatar') work? according to the docs, it looks like it should. Now all avatars would be defaults, but I checked with tinker and each of the relationships do return the avatar url, but not getting anything in the column. If I try using getStateUsing() to troubleshoot it, it says it only handles a string, which I would think wouldn’t be the case for multiple image support.
Solution:
looks like i had to append it like so:
protected $appends = ['avatar', 'phone'];
protected $appends = ['avatar', 'phone'];
...
Jump to solution
12 Replies
awcodes
awcodes16mo ago
are you getting null in the column or is the image being shrunk down by styling so that it looks like it isn't there?
Mark Chaney
Mark ChaneyOP16mo ago
hmm, just empty
<div class="fi-ta-image px-3 py-4"></div>
<div class="fi-ta-image px-3 py-4"></div>
. So if i do a TextColumn::make('belongsToManyRelationship.avatar'), i dont get anything either. I would think that would list the urls. If i do TextColumn::make('belongsToManyRelationship.name'), it does show the name
awcodes
awcodes16mo ago
weird and it's a stored column on the model? or is avatar an attribute on the model
Mark Chaney
Mark ChaneyOP16mo ago
attribute
Solution
Mark Chaney
Mark Chaney16mo ago
looks like i had to append it like so:
protected $appends = ['avatar', 'phone'];
protected $appends = ['avatar', 'phone'];
Mark Chaney
Mark ChaneyOP16mo ago
to the model
awcodes
awcodes16mo ago
that was my next question
Mark Chaney
Mark ChaneyOP16mo ago
why is it sometimes required and others not to access the attribute?
awcodes
awcodes16mo ago
i honestly don't know. it has frustrated me before too. Are you defining it the the Attribute cast or the old way?
Mark Chaney
Mark ChaneyOP16mo ago
had to do
public function getAvatarAttribute(): ?string
{
return Filament::getUserAvatarUrl($this);
}
public function getAvatarAttribute(): ?string
{
return Filament::getUserAvatarUrl($this);
}
to get avatars to work outside the panel
awcodes
awcodes16mo ago
just wondering if this still requires the appends:
public function avatar(): Attribute
{
return new Attribute(
get: fn () => Filament::getUserAvatarUrl($this)
);
}
public function avatar(): Attribute
{
return new Attribute(
get: fn () => Filament::getUserAvatarUrl($this)
);
}
It probably does, i'm just curious though.
Mark Chaney
Mark ChaneyOP16mo ago
nope. no biggie though
Want results from more Discord servers?
Add your server