Courses

Laravel Filament Admin v2: Practical Course

Validation Unique and Input Type Number

Previous: Labels for Fields: in Table and Forms
avatar

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.

avatar

@AlbertLens docs have unique rule with ignorable link to docs

avatar

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.

avatar
You can use Markdown
avatar
Carlos Capote Pérez Andreu

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.

👍 1
avatar
You can use Markdown
avatar
You can use Markdown