F
Filament14mo ago
Wiin

Relationship search in belongsTo select

Hello, is it possible to make a relationship search for a resource relationship? I have this for example: Forms\Components\Select::make('contact_id') ->relationship(name: 'contact', titleAttribute: 'email') ->searchable(['first_name', 'last_name', 'email', 'organisation.name']) ->required(), This is not working because 'organisation.name' is not a valid column. Is it possible to do it or do I have to do it differently so I can search contacts by their organisation name? Thank you!
3 Replies
tuto1902
tuto190214mo ago
tuto1902
tuto190214mo ago
One other option might be to use the modifyQueryUsing parameter of the relationship() method
->relationship(
name: 'contact',
modifyQueryUsing: fn (Builder $query) => $query->where('...'),
)
->relationship(
name: 'contact',
modifyQueryUsing: fn (Builder $query) => $query->where('...'),
)
Wiin
Wiin14mo ago
Will give it a try thanks!
Want results from more Discord servers?
Add your server