How to show more information in RelationManager Attach Search.

I have a RelationManager that allows users to Attach records from any of their authorized tenants. I would like to show the tenant name next to the line in the search box so the user knows they're attaching the record from the correct tenant. For example, if both tenants have records called "Corporate Department" I'd like the list in the search box to show as "Corporate Department (Tenant A), Corporate Department (Tenant B). I tried to use https://filamentphp.com/docs/3.x/panels/resources/relation-managers#searching-the-options-to-attach-across-multiple-columns but just got an error when i tried to use agency.name as one of my columns (as you would in the table builder).
Solution:
Just edited mine to be ... ```php Tables\Actions\AttachAction::make() ->recordSelectSearchColumns(['name', 'email'])...
Jump to solution
4 Replies
cheesegrits
cheesegrits14mo ago
You need recordTitle() ... here's how I do it, for pretty much the exact same reason, I need to add the user's email after the name, to make sure the right John Smith is selected ... "John Smith - [email protected]"
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['name', 'email'])
->recordTitle(function ($record) {
return sprintf('%s - %s', $record->name, $record->email);
})
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['name', 'email'])
->recordTitle(function ($record) {
return sprintf('%s - %s', $record->name, $record->email);
})
Note that I had to PR a fix on recordTitle() a week or so ago to make it work, so you'll need to be running a recent Filament version. And of course you can use a fat arrow fn() if you want, I think I just used a function(){} because I was debugging it. And I didn't typehint the $record, apparently. I'm going to hell.
Solution
cheesegrits
cheesegrits14mo ago
Just edited mine to be ...
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['name', 'email'])
->recordTitle(fn (User $record): string => sprintf('%s - %s', $record->name, $record->email))
Tables\Actions\AttachAction::make()
->recordSelectSearchColumns(['name', 'email'])
->recordTitle(fn (User $record): string => sprintf('%s - %s', $record->name, $record->email))
MarconiMamba
MarconiMambaOP14mo ago
so here's a question because I apparently don't know how to use composer. my composer.json is set for filament to be
"filament/filament": "3.0.*",
"filament/filament": "3.0.*",
but when I run artisan filament:upgrade and then composer show filament/filament it says i'm still on 3.0.73. I don't know what i'm doing wrong.
> composer show filament/filament
name : filament/filament
descrip. : A collection of full-stack components for accelerated Laravel app development.
keywords :
versions : * v3.0.73
> composer show filament/filament
name : filament/filament
descrip. : A collection of full-stack components for accelerated Laravel app development.
keywords :
versions : * v3.0.73
awcodes
awcodes14mo ago
“filament/filament”: “^3.0”
Want results from more Discord servers?
Add your server