Skip to content

Commit 37559ab

Browse files
committed
resolve namespaces
1 parent a39c9fa commit 37559ab

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/Console/ModelsCommand.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ public function getPropertiesFromMethods($model)
671671
$begin = strpos($code, 'function(');
672672
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
673673

674+
$customPivots = [];
675+
674676
foreach (
675677
$this->getRelationTypes() as $relation => $impl
676678
) {
@@ -716,20 +718,11 @@ public function getPropertiesFromMethods($model)
716718
if (!in_array($pivot, [Pivot::class, MorphPivot::class])) {
717719
$pivot = $this->getClassNameInDestinationFile($model, $pivot);
718720

719-
if ($existingPivot = ($this->properties[$relationObj->getPivotAccessor()] ?? null)) {
720-
// If the pivot is already set, we need to append the type to it
721-
$pivot .= '|' . $existingPivot['type'];
721+
if(isset($customPivots[$relationObj->getPivotAccessor()])){
722+
$customPivots[$relationObj->getPivotAccessor()][] = $pivot;
722723
} else {
723-
// pivots are not always set
724-
$pivot .= '|null';
724+
$customPivots[$relationObj->getPivotAccessor()] = [$pivot];
725725
}
726-
727-
$this->setProperty(
728-
$relationObj->getPivotAccessor(),
729-
$this->getClassNameInDestinationFile($model, $pivot),
730-
true,
731-
false
732-
);
733726
}
734727
}
735728

@@ -787,6 +780,15 @@ public function getPropertiesFromMethods($model)
787780
}
788781
}
789782
}
783+
784+
foreach($customPivots as $pivotAccessor => $pivots){
785+
$this->setProperty(
786+
$pivotAccessor,
787+
implode('|', $pivots) . '|null',
788+
true,
789+
false,
790+
);
791+
}
790792
}
791793
}
792794
}

tests/Console/ModelsCommand/Pivot/__snapshots__/Test__test__1.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
/**
1212
*
1313
*
14-
* @property-read \DifferentCustomPivot|\CustomPivot|null $pivot
1514
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationCustomPivotUsingSameAccessor
1615
* @property-read int|null $relation_custom_pivot_using_same_accessor_count
17-
* @property-read \CustomPivot|null $customAccessor
16+
* @property-read DifferentCustomPivot|null $pivot
1817
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithCustomPivot
1918
* @property-read int|null $relation_with_custom_pivot_count
20-
* @property-read \DifferentCustomPivot|null $differentCustomAccessor
19+
* @property-read CustomPivot|null $customAccessor
2120
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithDifferentCustomPivot
2221
* @property-read int|null $relation_with_different_custom_pivot_count
22+
* @property-read DifferentCustomPivot|null $differentCustomAccessor
2323
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithDifferentCustomPivotUsingSameAccessor
2424
* @property-read int|null $relation_with_different_custom_pivot_using_same_accessor_count
2525
* @method static \Illuminate\Database\Eloquent\Builder<static>|ModelWithPivot newModelQuery()

0 commit comments

Comments
 (0)