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 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']);
});


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'));
}),


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'));
}),
Was this page helpful?