Hiding a section based on Select field value

I have created a function where the 2nd section is hidden unless the Role selected from the 1st section is 'Vendor' which has an ID of '2'. It works fine, but when I edit a users with an existing 'Vendor' role. the 2nd section doesn't show up. I'd have to select a different role and select Vendor again for it to show up.

Group::make()
                    ->schema([
                        Section::make()
                            ->schema([
                                TextInput::make('name')->label('Full Name'),
                                TextInput::make('email')->label('Email'),
                                TextInput::make('password')->label('Password')
                                    ->password()
                                    ->dehydrateStateUsing(fn (string $state): string => Hash::make($state))
                                    ->dehydrated(fn (?string $state): bool => filled($state)),
                                Select::make('roles')
                                    ->native(false)
                                    ->relationship('roles', 'name')
                                    ->live()
                                    ->searchDebounce(500)
                            ]),
                        Section::make()
                            ->schema([
                                TextInput::make('user_rate')->label('Rate')
                                ->numeric(),
                                TextInput::make('user_distance_rate')->label('Rate Per Distance')
                                ->numeric(),
                                Toggle::make('user_preferred')->label('Preferred'),
                            ])
                            ->visible(fn (Get $get): bool => $get('roles') == 2)
                    ]),
Was this page helpful?