Skip to content

Commit bf0a994

Browse files
committed
fix: ensure correct morph class resolution in UniqueCustomFieldValue rule
Use `Relation::getMorphedModel` to resolve the actual entity class before determining the morph alias, improving compatibility with custom morph mappings.
1 parent 78cac14 commit bf0a994

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Rules/UniqueCustomFieldValue.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Closure;
88
use Illuminate\Contracts\Validation\ValidationRule;
9+
use Illuminate\Database\Eloquent\Relations\Relation;
910
use Relaticle\CustomFields\CustomFields;
1011
use Relaticle\CustomFields\Enums\CustomFieldsFeature;
1112
use Relaticle\CustomFields\FeatureSystem\FeatureManager;
@@ -54,7 +55,8 @@ private function existsOnAnotherEntity(string $normalizedValue): bool
5455
$valueColumn = $this->customField->getValueColumn();
5556

5657
$entityType = $this->customField->entity_type;
57-
$morphAlias = (new $entityType)->getMorphClass();
58+
$entityClass = Relation::getMorphedModel($entityType) ?? $entityType;
59+
$morphAlias = (new $entityClass)->getMorphClass();
5860

5961
$query = $valueModel->newQuery()
6062
->where('custom_field_id', $this->customField->getKey())

0 commit comments

Comments
 (0)