F
Filament2w ago
dyo

Listing multiple values in TextColumn with groupby a certain attribute

How can I Listing multiple values in TextColumn with groupby a certain attribute?
5 Replies
toeknee
toeknee2w ago
If it's a string:
->badge()
->separator(',')
->badge()
->separator(',')
Or you can do ->formatStateUsing(fn($record) => $data) and returnt he data in the format you want.
dyo
dyoOP2w ago
sorry if i'm not make it clear.. in above example, how can I group by the foreign key id of the relationship?
TextColumn::make('distribusi_penerima.penerima.id')
->bulleted()
->listWithLineBreaks()
->limitList(3)
->expandableLimitedList(),
TextColumn::make('distribusi_penerima.penerima.id')
->bulleted()
->listWithLineBreaks()
->limitList(3)
->expandableLimitedList(),
No description
toeknee
toeknee2w ago
What about:
TextColumn::make('distribusi_penerima.penerima.id')
->bulleted()
->listWithLineBreaks()
->formatStateUsing(fn($state) => array_unique($state))
->limitList(3)
->expandableLimitedList(),
TextColumn::make('distribusi_penerima.penerima.id')
->bulleted()
->listWithLineBreaks()
->formatStateUsing(fn($state) => array_unique($state))
->limitList(3)
->expandableLimitedList(),
Providing it is list of id's in an array
dyo
dyoOP2w ago
it returns error array_unique(): Argument #1 ($array) must be of type array, int given for now, I'm using accessor to solve my problem, but it makes the number of my queries in telescope to hundreds..
php
public function getGroupedPenerimaAttribute()
{
return $this->distribusi_penerima()->groupBy('penerima_id')->get();
}
php
public function getGroupedPenerimaAttribute()
{
return $this->distribusi_penerima()->groupBy('penerima_id')->get();
}
toeknee
toeknee2w ago
Sorry. If you removed the ID from the name space it probably would have worked maybe needed to process the the array first to make it into an id array

Did you find this page helpful?