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
# 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();
}),
]),
->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')