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)

but it keep return null in create and return coupon record not user in edit
Solution
@Neamix you should use 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})") 
Was this page helpful?