Wizard Get $get select multiple value based on filed

I've a form wizard like this:
public static function form(Form $form): Form
{
return $form
->schema([
...
Wizard\Step::make('Company')
->schema([
Forms\Components\Select::make('companies')
->relationship('companies', 'name')
->label('Select companies')
->options(Company::orderBy('name')->pluck('name', 'id')->toArray())
->multiple()
->searchable(['name'])
->live()
->required(),
Forms\Components\Select::make('owner_id')
->label('Select Lead company')
->options(function (Get $get) {

$companyIds = $get('companies');

if (empty($companyIds)) {
return Company::pluck('name', 'id')->toArray();
}

return Company::whereIn('id', $companyIds)
->pluck('name', 'id')
->toArray();
})->required(),
]),
...
public static function form(Form $form): Form
{
return $form
->schema([
...
Wizard\Step::make('Company')
->schema([
Forms\Components\Select::make('companies')
->relationship('companies', 'name')
->label('Select companies')
->options(Company::orderBy('name')->pluck('name', 'id')->toArray())
->multiple()
->searchable(['name'])
->live()
->required(),
Forms\Components\Select::make('owner_id')
->label('Select Lead company')
->options(function (Get $get) {

$companyIds = $get('companies');

if (empty($companyIds)) {
return Company::pluck('name', 'id')->toArray();
}

return Company::whereIn('id', $companyIds)
->pluck('name', 'id')
->toArray();
})->required(),
]),
...
1 Reply
ocram82
ocram824w ago
# continue from previous message


Wizard\Step::make('Coordinator')
->schema([
Forms\Components\Select::make('coordinator_id')
->label('Coordinator')
->options(function (Get $get) {

$companyIds = $get('companies');

if (empty($companyIds)) {
return [];
}

return User::whereIn('company_id', $companyIds)
->selectRaw("CONCAT(first_name, ' ', last_name) as full_name, id")
->pluck('full_name', 'id')
->toArray();
})
->required(),
]),
Wizard\Step::make('Empoyes')
->schema([
Forms\Components\Select::make('users')
->relationship('users')
->label('Empoyes')
->multiple()
->options(function (Get $get) {

$companyIds = $get('companies');

return User::whereIn('company_id', $companyIds)
->selectRaw("CONCAT(first_name, ' ', last_name) as full_name, id")
->pluck('full_name', 'id')
->toArray();
}),
]),
# continue from previous message


Wizard\Step::make('Coordinator')
->schema([
Forms\Components\Select::make('coordinator_id')
->label('Coordinator')
->options(function (Get $get) {

$companyIds = $get('companies');

if (empty($companyIds)) {
return [];
}

return User::whereIn('company_id', $companyIds)
->selectRaw("CONCAT(first_name, ' ', last_name) as full_name, id")
->pluck('full_name', 'id')
->toArray();
})
->required(),
]),
Wizard\Step::make('Empoyes')
->schema([
Forms\Components\Select::make('users')
->relationship('users')
->label('Empoyes')
->multiple()
->options(function (Get $get) {

$companyIds = $get('companies');

return User::whereIn('company_id', $companyIds)
->selectRaw("CONCAT(first_name, ' ', last_name) as full_name, id")
->pluck('full_name', 'id')
->toArray();
}),
]),
I don't know why inside Empoyes Wizard step the list of companies is not loaded and in the Coordinator wizard step yes Little update: i notice that if i remove ->relationship('users') from
Wizard\Step::make('Empoyes')
->schema([
Forms\Components\Select::make('users')
->relationship('users')
->label('Empoyes')
Wizard\Step::make('Empoyes')
->schema([
Forms\Components\Select::make('users')
->relationship('users')
->label('Empoyes')
it works on create but not in view or edit
Want results from more Discord servers?
Add your server