Eager loading relationships in table

I currently have this piece of code:
public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('last_name')
                    ->label(__('labels.name'))
                    ->getStateUsing(fn(Volunteer $record) => $record->person->fullName())
                    ->sortable()
                    ->searchable(['person.first_name', 'person.middle_name', 'person.last_name']),
                Tables\Columns\TextColumn::make('person.email')
                    ->label(__('labels.email'))
                    ->sortable()
                    ->searchable(),
                Tables\Columns\TextColumn::make('function')
                    ->label(__('labels.function'))
                    ->sortable()
                    ->searchable(),
            ])
            ->modifyQueryUsing(fn(Builder $query) => $query->with('person'))

When trying to search i get the error "SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "person" LINE 1: ...nt(*) as aggregate from "volunteers" where (lower(person.fir... ^"

Does anyone have an insight in how i might fix this? I thought the $query->with() would already solve it but unfortuantly it doesn't
Solution
Can you try using person.lastname as the name so that filament knows it’s a relation? 🤔
Was this page helpful?