Skip to content

Instantly share code, notes, and snippets.

@jlpellicer
Last active February 26, 2024 19:43
Show Gist options
  • Save jlpellicer/eb26270f4588c8332b883042bf70be64 to your computer and use it in GitHub Desktop.
Save jlpellicer/eb26270f4588c8332b883042bf70be64 to your computer and use it in GitHub Desktop.
How to get the selected option from a select input

Laravel 10 / Filament 3

Using Filament 3 and Laravel 10, if you want to get the label from a select you can use getOptions() to get an array of the options and use the $state (or Get works too) to get the value that you selected.

Forms\Components\Select::make('exchange_rate_id')
    ->relationship('exchange_rate', 'rate')
    ->searchable()
    ->preload()
    ->live() // don't miss this, it's important for this to work
    ->afterStateUpdated(function (Select $component, Set $set, string $state) {
        $val = $component->getOptions();
        $set('exchange_rate', $val[$state]);
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment