F
Filamentβ€’7mo ago
Jamie Cee

Unique field on a form

Having an issue and unsure the cause. I have a contact number field, and trying to add unique so that on update, it can ignore it.
Forms\Components\TextInput::make('contact_number')
->unique(ignorable: $form->getRecord())
->tel()
->maxLength(255),
Forms\Components\TextInput::make('contact_number')
->unique(ignorable: $form->getRecord())
->tel()
->maxLength(255),
But its not liking the checking the user. I can confirm the DB field is ID, and the uuid matches
No description
9 Replies
Jamie Cee
Jamie Ceeβ€’7mo ago
Also tried this:
->unique(app(Profile::class)->getTable(), 'contact_number', ignorable: $form->getRecord())
->unique(app(Profile::class)->getTable(), 'contact_number', ignorable: $form->getRecord())
toeknee
toekneeβ€’7mo ago
that is searching Arch_user_user.id which it is saying it is not found on arch_user_profiles
Jamie Cee
Jamie Ceeβ€’7mo ago
Ahh How would I tell it to look for the relation ID? So im editing a user currently, but contact number is in the profile table
toeknee
toekneeβ€’7mo ago
I haven't done that yet.... I suspect $form->getRecord() is the parent and you want to get the relationshipRecord right?
Jamie Cee
Jamie Ceeβ€’7mo ago
Yeah, so prior to the unique validation, it worked fine. Its just the case of the user update but not allowing duplicate contact numbers
toeknee
toekneeβ€’7mo ago
I am unsure tbh... I would be tempted to just fire in custom validation rule for it where not equal to this value in that table
Jamie Cee
Jamie Ceeβ€’7mo ago
Might be the easier approach at this point, just hoping a cleaner solution worked haha
toeknee
toekneeβ€’7mo ago
There should be a way to do it, but I personally haven't
Jamie Cee
Jamie Ceeβ€’7mo ago
Yeah, Id imagine so. Thanks anyway πŸ™‚ Still struggling to find a fix even with custom logic :/ Nevermind, found a solution. It was a simple dumb thing. I obviously was passing $form->getRecord() , but obviously its the profile relation, so I had to pass $form->getRecord()->profile