how to show a MorphOne table in filament Table?
I am struggling to access MorphOne relationship data in my table. I have Member model with MorphOne relationship with User and Company model. And I am trying display logo. But I am failing everytime. I use below code. I get repeat error saying .
11 Replies
Hi there, the docs show that you need to pass in a string (column in the database)
https://filamentphp.com/docs/3.x/tables/columns/image#overview
Hi @Tally .. thanks for quick response. Is not my return is string.
you then could use a ->formatStateUsing() to change the behaviour
You mean, i should choose any random 'string' in make() and use ->formatStateUsing() to define my callback.
yes.... call it profilepicture
🙂
But it say
Actually I have been able to one at a time either ImageColumn::make('memberable->profile_photo_path') or ImageColumn::make('memberable->profile->logo') for user or company but not generically for both depending upon member_type. since I have MorphOne elation.
Solution
you can use ->state()
then use your closure
thanks alot its working. So I can use ->state not just for image column rather anywhere for any morph relationship. Thanks alot.
normally if you set up the relation correctly you can use model.relationshipname.image_field
Sure @Tally . I was struggling with Morph relationship. Cause Table needs a way to know Model type.