JSON TextColumn formatStateUsing badge repeats

I am trying to show a badge for my JSON column. Everything works properly, but it repeats based on how many entries I have. I tried using limitList() however it will say "and X more".
Tables\Columns\TextColumn::make('attachments')
->formatStateUsing(fn ($state) => $state != null ? 'Attachment' : "")
->badge(),
Tables\Columns\TextColumn::make('attachments')
->formatStateUsing(fn ($state) => $state != null ? 'Attachment' : "")
->badge(),
Any help is appreciated πŸ™‚
Solution:
->state(fn ($record): string => $record->attachments ? 'Attachments' : '')
->badge()
->state(fn ($record): string => $record->attachments ? 'Attachments' : '')
->badge()
?...
Jump to solution
4 Replies
LeandroFerreira
LeandroFerreiraβ€’12mo ago
What is the output? Could you share an image please?
tommy_jeanslow
tommy_jeanslowOPβ€’12mo ago
It repeats the badge. In this case "Attachments". If the column is null, nothing displays. If there is one array within the json, one badge displays. If there are two arrays, two display, etc, etc.
Solution
LeandroFerreira
LeandroFerreiraβ€’12mo ago
->state(fn ($record): string => $record->attachments ? 'Attachments' : '')
->badge()
->state(fn ($record): string => $record->attachments ? 'Attachments' : '')
->badge()
?
tommy_jeanslow
tommy_jeanslowOPβ€’12mo ago
Thank you πŸ™‚ πŸ™‚
Want results from more Discord servers?
Add your server