requiredWithout validation

I am trying to run a requiredWithout validation rule, I want contact number to be required if email is null. The issue I am having is that contact number is inside the schema of a fieldset that is from the profile model. Where as email is on user directly.

                        Forms\Components\TextInput::make('contact_number')
                            ->unique(app(Profile::class)->getTable(), 'contact_number', $form->getRecord()->profile ?? null)
                            ->requiredWithout(function ($form) {
                                // return $form->getRecord()->email;
                                return $form->getComponent('email')->getValue();
                            })
                            ->tel()
                            ->maxLength(255),


This is my current attempt. But getting this error: An attempt was made to evaluate a closure for [Filament\Forms\Components\TextInput], but [$form] was unresolvable.

If I just have the requiredWithout('email') the validation is looking for data.profile.email which is incorrect as email isn't in profile, and if I call user.email its then searching data.profile.user.email
Was this page helpful?