getOptionLabelUsing is not working for custom option label result in Select

i cannot make it work using getOptionLabelUsing to make custom option label
image.png
Solution
Here you go. Try this. You'll need to adapt to your columns:

Forms\Components\Select::make('user')
    ->searchable()
    ->getSearchResultsUsing(fn (string $search): array => 
        User::where('name', 'like', "%{$search}%")
            ->limit(50)
            ->get()
            ->mapWithKeys(fn ($user) => 
                [$user->id => $user->name . ' - ' . $user->email]
            )
            ->toArray()
    )
    ->getOptionLabelUsing(function ($value): ?string {
        $user = User::find($value);
        return $user->name . ' - ' . $user->email;
    }),
Was this page helpful?