© 2026 Hedgehog Software, LLC

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

Customizing the Unique validation rule

How would I appropriately customize the Unique validation rule/method that Filament has according to the following?

Here is my
categories
categories
table:
Schema::create('categories', function (Blueprint $table) {
    $table->id();
    $table->foreignId('company_id')->constrained()->cascadeOnDelete();
    $table->string('name')->index();
    $table->string('type');
    $table->string('color');
    $table->boolean('enabled')->default(true);
    $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
    $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
    $table->timestamps();

    $table->unique(['company_id', 'name', 'type']);
});
Schema::create('categories', function (Blueprint $table) {
    $table->id();
    $table->foreignId('company_id')->constrained()->cascadeOnDelete();
    $table->string('name')->index();
    $table->string('type');
    $table->string('color');
    $table->boolean('enabled')->default(true);
    $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
    $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
    $table->timestamps();

    $table->unique(['company_id', 'name', 'type']);
});


This is what I have so far for the Field:
Forms\Components\TextInput::make('name')
  \\ ...
  ->unique(modifyRuleUsing: static function (Unique $rule, Request $request) {
      return $rule->where('company_id', auth()->user()->currentCompany->id)
                  ->where('type', $request->input('type'));
}),
Forms\Components\TextInput::make('name')
  \\ ...
  ->unique(modifyRuleUsing: static function (Unique $rule, Request $request) {
      return $rule->where('company_id', auth()->user()->currentCompany->id)
                  ->where('type', $request->input('type'));
}),


Will the above work? Or do I need to do something like this or something else?
Forms\Components\TextInput::make('name')
  \\ ...
  ->unique(modifyRuleUsing: static function (Unique $rule, Forms\Get $get) {
      return $rule->where('company_id', auth()->user()->currentCompany->id)
                  ->where('type', $get('type'));
}),
Forms\Components\TextInput::make('name')
  \\ ...
  ->unique(modifyRuleUsing: static function (Unique $rule, Forms\Get $get) {
      return $rule->where('company_id', auth()->user()->currentCompany->id)
                  ->where('type', $get('type'));
}),
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 validation rule in repeater
FilamentFFilament / ❓┊help
3y ago
Unique validation rule not applicable to db index
FilamentFFilament / ❓┊help
8mo ago
Unique validation
FilamentFFilament / ❓┊help
2y ago
unique validation
FilamentFFilament / ❓┊help
3y ago