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(),
]),
...