© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
6 replies
Jamie Cee

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),
                        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
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Issue with requiredWithout validation
FilamentFFilament / ❓┊help
2y ago
requiredWithout() with repeater field being the requirement
FilamentFFilament / ❓┊help
3y ago
validation
FilamentFFilament / ❓┊help
2y ago
validation
FilamentFFilament / ❓┊help
3y ago