How to dynamically populate select option label using the Form Builder

Hi,

I am using the Select field of the form builder.

I want to use the city names from my City model to populate the option label. If I have to do it manually it would look like this.

protected function getFormSchema(): array
{
return [
Select::make('city')
->options([
'miami' => 'Miami',
'boston' => 'Boston',
'denver' => 'Denver,
])->searchable(),

];
}

What if I wanted to dynamically pull these city from the database. I assume it would look like this but obviously this does not work

protected function getFormSchema(): array
{
return [
Select::make('city')
->options([
City::all()->pluck('city')
])->searchable(),

];
}
Was this page helpful?