How can I sort a table using a relationship?

In a column I have this relationship:

        return $table
            ->columns([
                Tables\Columns\TextColumn::make('enterprise.name')
                    ->label('Empreendimento')
                    ->sortable()
                    ->searchable(),
         ...


How can I apply a default sort?

I try it, but this is not work!
            ->defaultSort(function ($query, $direction) {
                $query->orderBy('enterprise.name');
            })
Solution
->defaultSort('enterprise.name')
Was this page helpful?