class Competition extends Model
{
public function squads()
{
return $this->belongsToMany(Squad::class)->join('clubs', 'club_id', '=', 'clubs.id')->orderBy('clubs.name');
}
}class Squad extends Model
{
public function club()
{
return $this->belongsTo(Club::class);
}
}class SquadsRelationManager extends RelationManager
{
protected static string $relationship = 'squads';
protected static ?string $recordTitleAttribute = 'clubs.name';
public function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('club.name'),
])
}
}Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['clubs.name'])
->recordTitle(fn (Squad $record): string => "{$record->club->name} ({$record->id})"),