Inject $relatedRecord in TextColumn and TextEntry closures to customize each item

Inject $relatedRecord in TextColumn and TextEntry closures to customize each item

  • table
  • infolist
  • relationshipt
PR #20633 by @danharrin

When a column or entry shows several values from a relationship, like tags.name, the closures that style each item can now take $relatedRecord. That's the related model behind that one item. It's only filled in per item, so use it with badge() or listWithLineBreaks(). The $record parameter is still the parent row. A plain comma-joined list gets styled as a whole.

E.g: on a Posts table, you can color each tag badge with the hex color saved on its Tag model, instead of looking it up by name.

TextColumn::make('tags.name')
    ->badge()
    ->color(fn (Tag $relatedRecord): string => $relatedRecord->color)
TextEntry::make('tags.name')
    ->badge()
    ->color(fn (Tag $relatedRecord): string => $relatedRecord->color)
All Filament Up To Date tips