F
Filament14mo ago
MeniV

Counting relations in infolist

I'm trying to show the nr. of relationships (rows) from a one-to-many relationship on a infolist. Tried a lot, nothing worked. I think it may can be done with a placeholder? How exactly?
Solution:
TextEntry::make('total')
->getStateUsing(fn ($record) => $record->xxx->count())
TextEntry::make('total')
->getStateUsing(fn ($record) => $record->xxx->count())
?...
Jump to solution
3 Replies
Solution
LeandroFerreira
LeandroFerreira14mo ago
TextEntry::make('total')
->getStateUsing(fn ($record) => $record->xxx->count())
TextEntry::make('total')
->getStateUsing(fn ($record) => $record->xxx->count())
?
MeniV
MeniVOP14mo ago
Thanks!
Wallace Vizerra
Wallace Vizerra12mo ago
Another way to do this is like this:
public static function infolist(Infolist $infolist): Infolist
{
$infolist->getRecord()->loadCount('authors');

return $infolist->schema([
// ...
TextEntry::make('authors_count')->label('Authors')
]);
}
public static function infolist(Infolist $infolist): Infolist
{
$infolist->getRecord()->loadCount('authors');

return $infolist->schema([
// ...
TextEntry::make('authors_count')->label('Authors')
]);
}
Want results from more Discord servers?
Add your server