Formatting dates returned in multi-relationship table column?

I have a table column that references a many-to-many relationship field, and I want to display a formatted version of a date field/attribute on the related models that are returned. Right now the column state comes as a comma-separated list of whatever default Carbon formatting is in place. Before I go down the road of splitting out those text values in $state so I can re-parse and re-format them (!), is there a better way to format the individual values of relationships returned? Thanks.
Solution:
I'm trying this for now, seems to be working:
TextColumn::make('printIssues.issue_date')
->getStateUsing(fn($record) => $record->printIssues->pluck('formatted_date'))
->badge(),
TextColumn::make('printIssues.issue_date')
->getStateUsing(fn($record) => $record->printIssues->pluck('formatted_date'))
->badge(),
...
Jump to solution
1 Reply
Solution
ChrisHardie
ChrisHardie9mo ago
I'm trying this for now, seems to be working:
TextColumn::make('printIssues.issue_date')
->getStateUsing(fn($record) => $record->printIssues->pluck('formatted_date'))
->badge(),
TextColumn::make('printIssues.issue_date')
->getStateUsing(fn($record) => $record->printIssues->pluck('formatted_date'))
->badge(),
Want results from more Discord servers?
Add your server