return $form
->schema([
Forms\Components\Group::make()->schema([
Forms\Components\Section::make()->schema([
Forms\Components\TextInput::make('name')
->label('Name')
->required()
->placeholder('John Doe')
->maxLength(255)
->columns(2),
Forms\Components\TextInput::make('email')
->label('Email')
->required()
->columns(2),
Forms\Components\Select::make('type')
->label('Type')
->options(UserRoles::toArray())
->afterStateUpdated(function (Get $get, Set $set) {
if ($get('type') == UserRoles::CUSTOMER->value) {
$set('groups', null);
}
})
->live()
->required(),
Forms\Components\Select::make('groups')
->relationship('groups')
->label('Groups')
->options(Group::all()->pluck('name', 'id'))
->multiple()
->required()
->hidden(fn(Get $get) => $get('type') == UserRoles::CUSTOMER->value),
])->columns(2),
])->columnSpanFull(),
]);
return $form
->schema([
Forms\Components\Group::make()->schema([
Forms\Components\Section::make()->schema([
Forms\Components\TextInput::make('name')
->label('Name')
->required()
->placeholder('John Doe')
->maxLength(255)
->columns(2),
Forms\Components\TextInput::make('email')
->label('Email')
->required()
->columns(2),
Forms\Components\Select::make('type')
->label('Type')
->options(UserRoles::toArray())
->afterStateUpdated(function (Get $get, Set $set) {
if ($get('type') == UserRoles::CUSTOMER->value) {
$set('groups', null);
}
})
->live()
->required(),
Forms\Components\Select::make('groups')
->relationship('groups')
->label('Groups')
->options(Group::all()->pluck('name', 'id'))
->multiple()
->required()
->hidden(fn(Get $get) => $get('type') == UserRoles::CUSTOMER->value),
])->columns(2),
])->columnSpanFull(),
]);