Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #422
    dan
    Participant

    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 is not works

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

    ];
    }

    #423

    that’s already good, just remove the square brackets inside option as follows:

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

    ];
    }

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.