F
Filament2mo ago
mxc

Infolist - belongsToMany collection.count not rendering?

Hi all< I have 2 eloguent models with a many to many relations. I know the relationship is set up correctly in eloquent as a RepeatableEntry filed renders the individual members of the collection properly. I also want to output the count of the items in the collection with: TextEntry::make('declines.count') ->Label("Quotes Declined") ->numeric(), But I don't get anything displayed and no error messages. This works and displays the individual memebers. RepeatableEntry::make('declines') ->schema([ TextEntry::make('name') ->bulleted() ->hiddenLabel(), ])->contained(false), Any help appreciated.t
18 Replies
Dennis Koch
Dennis Koch2mo ago
You can select the state directly: ->state(fn ($record) => $record->declines->count()) Or modify the DB query to return the counts and then access them via decline_counts
LeandroFerreira
LeandroFerreira2mo ago
TextEntry::make('declines_count')
->counts('declines')
TextEntry::make('declines_count')
->counts('declines')
Dennis Koch
Dennis Koch2mo ago
And I thought that one doesn't exist, because it's not mentioned in the docs 😅
LeandroFerreira
LeandroFerreira2mo ago
I think this is new in v4 😅
mxc
mxcOP2mo ago
Thanks. I am using v4 but couldn't get the ->count('declines') to work so when with the ->state option. The ->count is more elegant if I could get it to work.
LeandroFerreira
LeandroFerreira2mo ago
php artisan filament:about what is the output?
Dennis Koch
Dennis Koch2mo ago
And can you share the exact code you used?
mxc
mxcOP2mo ago
Hi @LeandroFerreira Here is the output: Filament .........................................................................................................................................
Blade Icons ........................................................................................................................... NOT CACHED
Packages ................................................... filament, forms, notifications, support, tables, actions, infolists, schemas, widgets
Panel Components ...................................................................................................................... NOT CACHED
Version ................................................................................................................................... v4.0.3
Views .............................................................................................................................. NOT PUBLISHED
Dennis Koch
Dennis Koch2mo ago
Did you use declines_count as the name?
LeandroFerreira
LeandroFerreira2mo ago
counts, not count
LeandroFerreira
LeandroFerreira2mo ago
GitHub
filament/packages/infolists/src/Components/TextEntry.php at v4.0.3 ...
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire - filamentphp/filament
mxc
mxcOP2mo ago
Here is the code: ComponentsSection::make('Details') ->description('Details') ->columns(3)->schema( [ TextEntry::make('matching_vendors_count') ->Label("Invited") ->numeric(), TextEntry::make('vendorDeclines_count') ->state(fn($record) => $record->vendorDeclines->count()) ->Label("Declined") ->numeric(), TextEntry::make('vendorOffers_count') ->state(fn($record) => $record->vendorOffers->count()) ->Label("Tendered") ->numeric(), RepeatableEntry::make('vendors') ->label("Invited") ->schema([ TextEntry::make('name') ->bulleted() ->hiddenLabel(), ])->contained(false), RepeatableEntry::make('vendorDeclines') ->label("Declined") ->schema([ TextEntry::make('name') ->bulleted() ->hiddenLabel(), ])->contained(false), RepeatableEntry::make('vendorOffers') ->label("Tendered") ->schema([ TextEntry::make('name') ->bulleted() ->hiddenLabel(), ])->contained(false) ] ),
LeandroFerreira
LeandroFerreira2mo ago
And what part of this code is using my example? Did you see my example?
mxc
mxcOP2mo ago
TextEntry::make('vendorOffers_count') ->state(fn($record) => $record->vendorOffers->count()) ->Label("Tendered") ->numeric(), The 2nd line doesn't work with ->counts() I will investigate further.
LeandroFerreira
LeandroFerreira2mo ago
TextEntry::make('vendor_offers_count')->counts('vendor_offers')
Dennis Koch
Dennis Koch2mo ago
For the future: Please use markdown to format your code. That makes it more readable.
mxc
mxcOP2mo ago
i tried to find the format button but can't. I have used it before. It seems the interface has changed. Will try and locate it.
Dennis Koch
Dennis Koch2mo ago
It’s markdown, or triple backticks. You can find an example in the #✅┊rules

Did you find this page helpful?