Skip to content

Commit d7806bd

Browse files
committed
Revert "resolve namespaces"
This reverts commit 37559ab.
1 parent 37559ab commit d7806bd

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/Console/ModelsCommand.php

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

674-
$customPivots = [];
675-
676674
foreach (
677675
$this->getRelationTypes() as $relation => $impl
678676
) {
@@ -718,11 +716,20 @@ public function getPropertiesFromMethods($model)
718716
if (!in_array($pivot, [Pivot::class, MorphPivot::class])) {
719717
$pivot = $this->getClassNameInDestinationFile($model, $pivot);
720718

721-
if(isset($customPivots[$relationObj->getPivotAccessor()])){
722-
$customPivots[$relationObj->getPivotAccessor()][] = $pivot;
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'];
723722
} else {
724-
$customPivots[$relationObj->getPivotAccessor()] = [$pivot];
723+
// pivots are not always set
724+
$pivot .= '|null';
725725
}
726+
727+
$this->setProperty(
728+
$relationObj->getPivotAccessor(),
729+
$this->getClassNameInDestinationFile($model, $pivot),
730+
true,
731+
false
732+
);
726733
}
727734
}
728735

@@ -780,15 +787,6 @@ public function getPropertiesFromMethods($model)
780787
}
781788
}
782789
}
783-
784-
foreach($customPivots as $pivotAccessor => $pivots){
785-
$this->setProperty(
786-
$pivotAccessor,
787-
implode('|', $pivots) . '|null',
788-
true,
789-
false,
790-
);
791-
}
792790
}
793791
}
794792
}

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
1415
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationCustomPivotUsingSameAccessor
1516
* @property-read int|null $relation_custom_pivot_using_same_accessor_count
16-
* @property-read DifferentCustomPivot|null $pivot
17+
* @property-read \CustomPivot|null $customAccessor
1718
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithCustomPivot
1819
* @property-read int|null $relation_with_custom_pivot_count
19-
* @property-read CustomPivot|null $customAccessor
20+
* @property-read \DifferentCustomPivot|null $differentCustomAccessor
2021
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithDifferentCustomPivot
2122
* @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)