File tree Expand file tree Collapse file tree 8 files changed +21
-1
lines changed
Filament/Management/Schemas Expand file tree Collapse file tree 8 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ public function __construct(
2828 public bool $ withoutUserOptions = false ,
2929 public bool $ acceptsArbitraryValues = false ,
3030 public bool $ supportsMultiValue = false ,
31+ public bool $ supportsUniqueConstraint = false ,
3132 public array $ validationRules = [],
3233 public ?string $ settingsDataClass = null ,
3334 public string |Closure |null $ settingsSchema = null ,
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public function configure(): FieldSchema
3030 ->searchable ()
3131 ->sortable ()
3232 ->supportsMultiValue ()
33+ ->supportsUniqueConstraint ()
3334 ->withArbitraryValues ()
3435 ->withoutUserOptions ()
3536 ->availableValidationRules ([
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public function configure(): FieldSchema
2626 ->formComponent (LinkComponent::class)
2727 ->tableColumn (TextColumn::class)
2828 ->infolistEntry (TextEntry::class)
29+ ->supportsUniqueConstraint ()
2930 ->priority (60 )
3031 ->availableValidationRules ([
3132 ValidationRule::REQUIRED ,
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public function configure(): FieldSchema
2626 ->formComponent (NumberComponent::class)
2727 ->tableColumn (TextColumn::class)
2828 ->infolistEntry (TextEntry::class)
29+ ->supportsUniqueConstraint ()
2930 ->priority (20 )
3031 ->availableValidationRules ([
3132 ValidationRule::REQUIRED ,
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ public function configure(): FieldSchema
2727 ->tableColumn (TextColumn::class)
2828 ->infolistEntry (TextEntry::class)
2929 ->encryptable ()
30+ ->supportsUniqueConstraint ()
3031 ->priority (10 )
3132 ->availableValidationRules ([
3233 ValidationRule::REQUIRED ,
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public function configure(): FieldSchema
2626 ->formComponent (TextareaFormComponent::class)
2727 ->tableColumn (TextColumn::class)
2828 ->infolistEntry (TextEntry::class)
29+ ->supportsUniqueConstraint ()
2930 ->priority (15 )
3031 ->availableValidationRules ([
3132 ValidationRule::REQUIRED ,
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ class FieldSchema
5555
5656 private bool $ supportsMultiValue = false ;
5757
58+ private bool $ supportsUniqueConstraint = false ;
59+
5860 protected bool $ withoutUserOptions = false ;
5961
6062 private ?string $ settingsDataClass = null ;
@@ -323,6 +325,16 @@ public function supportsMultiValue(bool $supports = true): self
323325 return $ this ;
324326 }
325327
328+ /**
329+ * Configure whether field supports unique value constraint per entity type
330+ */
331+ public function supportsUniqueConstraint (bool $ supports = true ): self
332+ {
333+ $ this ->supportsUniqueConstraint = $ supports ;
334+
335+ return $ this ;
336+ }
337+
326338 // ========== Data Type Specific Methods (from DataTypeConfigurators) ==========
327339
328340 /**
@@ -555,6 +567,7 @@ public function data(): FieldTypeData
555567 withoutUserOptions: $ this ->withoutUserOptions ,
556568 acceptsArbitraryValues: $ this ->acceptsArbitraryValues ,
557569 supportsMultiValue: $ this ->supportsMultiValue ,
570+ supportsUniqueConstraint: $ this ->supportsUniqueConstraint ,
558571 validationRules: $ this ->availableValidationRules ,
559572 settingsDataClass: $ this ->settingsDataClass ,
560573 settingsSchema: $ this ->settingsSchema
Original file line number Diff line number Diff line change @@ -405,7 +405,8 @@ public static function schema(bool $withOptionsRelationship = true): array
405405 )
406406 )
407407 ->visible (
408- fn (): bool => FeatureManager::isEnabled (CustomFieldsFeature::FIELD_UNIQUE_VALUE )
408+ fn (Get $ get ): bool => FeatureManager::isEnabled (CustomFieldsFeature::FIELD_UNIQUE_VALUE ) &&
409+ CustomFieldsType::getFieldType ($ get ('type ' ))?->supportsUniqueConstraint === true
409410 )
410411 ->default (false ),
411412 ]),
You can’t perform that action at this time.
0 commit comments