Laravel Orchid preselect a value in a Select

711 Views Asked by At

i have a question.

according to the Documentation of Laravel orchid an empty Select can be added this way : https://orchid.software/en/docs/field/#select

// For array
Select::make('user')
    ->options([
        1  => 'Option 1',
        2  => 'Option 2',
    ])
    ->empty('No select');

// For model
Select::make('user')
    ->fromModel(User::class, 'name')
    ->empty('No select');

how ever, when i try it out it does not show me my empty Select in my code , when i add the second vale a 0 as key it shows me the empty one.

but how can i make it as default when the page is loaded?

this is my Layout :

protected function layouts(): array
    {
        $systems = OperatingSystem::pluck('name', 'id')->toArray();
        $versions = $this->query->get('operating_system_id') ?
            OperatingSystemVersion::where('operating_system_id', $this->query->get('operating_system_id'))->pluck('version', 'id')
            : $this->query['versions'];

        return [
            Layout::rows([
                Group::make([
                    Select::make('operating_system_id')
                        ->title('System Name')
                        ->set('options', $systems)
                        ->empty('No os Selected', 0),

                    Select::make('versions.id')
                        ->title('Version Name')
                        ->set('options', $versions)
                        ->empty(),
                ]),
            ])
        ];
    }
0

There are 0 best solutions below