F
Filament2y ago
Xavi

Get current record

How can i get current record on a table builder to show a relationship field on a column I try this, but it doesnt works
TextColumn::make('google_users')
->label('Google Users')
->getStateUsing(function (User $user) {
return $user->googleUsers()->count();
})
->sortable(),
TextColumn::make('google_users')
->label('Google Users')
->getStateUsing(function (User $user) {
return $user->googleUsers()->count();
})
->sortable(),
3 Replies
toeknee
toeknee2y ago
You just call the relationship with dot syntax use
TextColumn::make('google_users.count')
->label('Google Users')
->sortable(),
TextColumn::make('google_users.count')
->label('Google Users')
->sortable(),
Dennis Koch
Dennis Koch2y ago
You need to keep the variable naming. It would be $record not $user Btw. there is a ->counts() method
Xavi
XaviOP2y ago
great Dennis, thank you so much!
Want results from more Discord servers?
Add your server