© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
Neamix

Add relation in select menu

Hey folks, i have 2 models coupons and users and each coupons belongsTo one user and each user have firstname and surname so i want to create a select menu contain users firstname and surname i tried to use this
Select::make('user_id')
                ->relationship(name: 'user', titleAttribute: function ($record) {
                    dd($record);
                })
                ->searchable()
                ->optionsLimit(20)
Select::make('user_id')
                ->relationship(name: 'user', titleAttribute: function ($record) {
                    dd($record);
                })
                ->searchable()
                ->optionsLimit(20)

but it keep return null in create and return coupon record not user in edit
Solution
@Neamix you should use
getOptionLabelFromRecordUsing()
getOptionLabelFromRecordUsing()


Here's the example from one of our tutorials:

Forms\Components\Select::make('car_id')
    ->relationship(
        name: 'car'
    )
    ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->name} ({$record->year})") 
Forms\Components\Select::make('car_id')
    ->relationship(
        name: 'car'
    )
    ->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->name} ({$record->year})") 
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Customize Select in Relation Manager
FilamentFFilament / ❓┊help
12mo ago
Two level relation in select
FilamentFFilament / ❓┊help
3y ago
Select Filter with relation
FilamentFFilament / ❓┊help
3y ago
Select field hasMany relation
FilamentFFilament / ❓┊help
3y ago