Skip to main content

Validation Unique and Input Type Number

Premium
2:29

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

A
AlbertLens ✓ Link copied!

I have found a problem with the ->unique() validation.

Everything is fine when trying to create a new one, but if I try to edit, make no changes at all to that field with the unique validation (or even no changes in any fields at all), and try to save changes, you get the error of

The code has already been taken.

Any ideas of how to solve this for the edit form in Filament, please?

Tks.

N
Nerijus ✓ Link copied!

@AlbertLens docs have unique rule with ignorable link to docs

A
AlbertLens ✓ Link copied!

Tks very much. I had missed that "little" part in the official docs.

Now, with ->unique(ignoreRecord: true) it is working perfectly.

Thanks once more.

CC
Carlos Capote Pérez Andreu ✓ Link copied!

As part of my follow up of the course, I tried to implement a zip code validation that included different validations depending on the country of the address. And I found that the way Filament passes data to validation rules is different depending on where the validation is being used from.

In case someone is interested, I created this discussion with more details: https://github.com/filamentphp/filament/discussions/6521.