Display value of Pivot Table
Hello,
I'm currently looking for a better and more performant solution to display a pivot table attribute in my relationManager.
It is working right now and using formatStateUsing() but it is doing a lot of DB queries as you might see i use the SponsorType::find() function.
SponsorsRelationManager.php
10 Replies
Pivot Class: ConferenceSponsor.php
Sponsor model class:
can you not just eager load the relationship in the eloquent query for the table?
Where exactly would i need to do that? Sorry im quite new to this
In your relation manage class I think it’s getTableQuery.
Works the same as the list resource class. https://filamentphp.com/docs/2.x/admin/resources/listing-records#customizing-the-eloquent-query
Filament
Listing records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Added this code now and i don't get n+1 warning anymore. This should mean the eager loading is working correct?
correct
then you should be able to just use 'sponsorType.name' for your text column
Thanks it worked 🙂