© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•9mo ago•
10 replies
JJSanders

Unique rule not working on update

Hello,

I have this unique rule:

  TextInput::make('item_code')
      ->label('Artikelcode')
      ->required()
      ->maxLength(255)
      ->rule(function (Get $get) {
          return Rule::unique('products', 'item_code')
              ->where(fn ($query) => $query->where('brand_id', $get('brand_id')))
              ->ignore(request()->route('record'));
      }),
  TextInput::make('item_code')
      ->label('Artikelcode')
      ->required()
      ->maxLength(255)
      ->rule(function (Get $get) {
          return Rule::unique('products', 'item_code')
              ->where(fn ($query) => $query->where('brand_id', $get('brand_id')))
              ->ignore(request()->route('record'));
      }),

However when updating the record i also get the error message that it is not unique.

This shouldn't be the case. How can I make this rule only validate on creating records and not on updating records?
Solution
I figured it out. I had extra code in the creating and updating hooks off my model which interfered with the validation logic
Jump to solution
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

unique is not working
FilamentFFilament / ❓┊help
3y ago
Unique rule with MorphToSelect fields
FilamentFFilament / ❓┊help
3y ago
Customizing the Unique validation rule
FilamentFFilament / ❓┊help
3y ago
Unique validation rule in repeater
FilamentFFilament / ❓┊help
3y ago