F
Filament15mo 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
toeknee15mo 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 Koch15mo ago
You need to keep the variable naming. It would be $record not $user Btw. there is a ->counts() method
Xavi
Xavi15mo ago
great Dennis, thank you so much!