© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
9 replies
Wirkhof

Modifying the option label in Select

I would like to modify the option's label in the select box.

My working code without any added text looks like this:
->schema([
    Select::make('user_id')
        ->label('Warrior')
        ->required()
        ->searchable()
        ->options(User::all()->pluck('name', 'id')
])
->schema([
    Select::make('user_id')
        ->label('Warrior')
        ->required()
        ->searchable()
        ->options(User::all()->pluck('name', 'id')
])


And this works and the user names are shown based on what you type in the select box.

I would like to add a custom text (I will replace it later with a custom generated quote like "I only trust my sword" etc.)
at the end of the name.

So, instead of what I have now:

Jar Grimsh
Witek Boiar
Zilgert Brimbright
Jar Grimsh
Witek Boiar
Zilgert Brimbright


I would want:

Jar Grimsh - I only trust my sword.
Witek Boiar - War, war, and war!
Zilgert Brimbright - Light over darkness.
Jar Grimsh - I only trust my sword.
Witek Boiar - War, war, and war!
Zilgert Brimbright - Light over darkness.


In the results in the select box as the user is typing stuff in it.

How to alter the option output to reflect the added text?

Let's say the labels are stored in the table called
quotes
quotes
and they have an
id
id
and
quote
quote
for the quote itself. And it should be random.

Or just with a custom static text or html like
 - my custom quote
 - my custom quote
or
<b style='color: green;'> - my custom quote</b>
<b style='color: green;'> - my custom quote</b>


I have tried suggestions my some Discord users like:

->schema([
    Select::make('user_id')
        ->label('Warrior')
        ->required()
        ->searchable()
        ->options(User::all()->pluck('name', 'id')
        ->getOptionLabelFromRecordUsing(fn(Model $record) => "{$record->name} - my custom text")
])
->schema([
    Select::make('user_id')
        ->label('Warrior')
        ->required()
        ->searchable()
        ->options(User::all()->pluck('name', 'id')
        ->getOptionLabelFromRecordUsing(fn(Model $record) => "{$record->name} - my custom text")
])

But this is not working and the output is still just the name. The part " - my custom text" is missing.
Solution
maybe something like this.
Select::make('user_id')
  ->label('Warrior')
  ->required()
  ->searchable()
  ->options(function(): array {
      return User::all()->mapWithKeys(function ($user) {
          return [$user->id => $user->name . ' - ' . $user->quote];
      })->toArray();
  })
Select::make('user_id')
  ->label('Warrior')
  ->required()
  ->searchable()
  ->options(function(): array {
      return User::all()->mapWithKeys(function ($user) {
          return [$user->id => $user->name . ' - ' . $user->quote];
      })->toArray();
  })
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Custom option label in multiple select
FilamentFFilament / ❓┊help
3y ago
Selected option's label does not update in select field
FilamentFFilament / ❓┊help
3y ago
Prevent select option re-rendering in SelectInput
FilamentFFilament / ❓┊help
3y ago
How the get the option label from a select
FilamentFFilament / ❓┊help
2y ago