FilamentF
Filament2y ago
Veur

TextColumn with subquery value

I have a Filament Table (outside a panel) listing records from a relationship.
In the select statement of the query I added a subquery, which counts a certain number of records.
But the value from the subquery isn't displayed in the table. While I see the attribute has a value when I dd() the query.
Any ideas? Below is the $table code:
public function table(Table $table): Table
{
    return $table
        ->relationship(fn (): HasMany => $this->user->clients()
            ->addSelect([
                'vacancies_count' => Vacancy::query()
                    ->selectRaw('COUNT(*)')
                    ->whereColumn('client_id', 'teams.id')
                    ->active()
            ])
        )
        ->inverseRelationship('user')
        ->columns([
            TextColumn::make('vacancies_count')
                ->sortable(),
        ]);
}
Was this page helpful?