Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

earmsby's avatar

Search results in Attach method

In a Filament 4 relation manager I have an attach method like this:

AttachAction::make()
                    ->label('Link Existing Account')
                    ->schema(fn(AttachAction $action): array => [
                        $action->getRecordSelect(),
                        Select::make('author_role')
                            ->options(function () {
                                return CreatorRole::orderBy('creator_role_name')->pluck('creator_role_name', 'creator_role_name')->toArray();
                            })
                            ->required(),
                    ])
                    ->preloadRecordSelect()
                    ->modalHeading('Link Account')
                    ->modalSubmitActionLabel('Link')
                    ->recordSelectOptionsQuery(function ($query) {
                        //limit accounts shown to only those with a role=2 (authors)
                        return $query->whereHas('roles', function ($query) {
                            $query->where('id', 2);
                        });
                    })
                    ->recordTitle(function ($record) {
                        return $record->display_name;
                    })

The modal shows a list of accounts and displays the "display name" of each account. However, when I try to search for the account, the results match only the title attribute for the record which is "account_number." I'm guessing that's due to this in the relation manager:

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('account_number')
            ->columns([
                TextColumn::make('account_number')
                    ->label('Account ID')
                    ->searchable(),
                TextColumn::make('display_name')
                    ->label('Account Name')
                    ->searchable(),
                TextColumn::make('author_role')
                    ->label('Role')
                    ->searchable()
                    ->default('No Creator Role'),
            ])

So, for example if I have these accounts:

  • A-6FSX6JYY : Paul Carey
  • A-7MAALNQT : Subito Music Corp.
  • A-T2OM4SXP : Kander, Susan
  • A-WVNC211M : Schmoe, Joe

and I type "S" in the search on the modal, the results are:

  • Paul Carey
  • Kander, Susan

because these two have "S" in the account number. But I'm expecting results of:

  • Subito Music Corp.
  • Kander, Susan
  • Schmoe, Joe

Is there a way to have the modal search other fields?

0 likes
2 replies
LaryAI's avatar
Level 58

Yes, you can customize which attributes are searchable in the Filament AttachAction modal. By default, the modal's search uses the recordTitleAttribute (in your case, account_number), but you can extend this to additional columns.

For Eloquent relations in Filament v4, the getRecordSelectSearchColumns() method (on the Relation Manager) controls which fields are searched in the AttachAction modal.

Here's how to add this to your relation manager:

class AccountRelationManager extends RelationManager
{
    // ...

    public static function getRecordSelectSearchColumns(): array
    {
        // Add each column you want to be searchable
        return ['account_number', 'display_name'];
    }

    // ...
}

Explanation:

  • By overriding getRecordSelectSearchColumns() and returning an array of column names, Filament will search all listed columns in the Attach modal.
  • Now, if you search "S", it will also match any record where the display_name contains "S", not just account_number.

References:

Summary:
Override getRecordSelectSearchColumns() in your relation manager to include both account_number and display_name. This will allow the Attach modal to search both fields as you expect.

earmsby's avatar

Adding that function did not work. But I added this to the AttachAction:

->recordSelectSearchColumns(['display_name','last_name', 'first_name','org_name','email'])

and that did the trick

Please or to participate in this conversation.