Skip to content

Commit

Permalink
resolve namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pataar committed Oct 18, 2024
1 parent a39c9fa commit 37559ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ public function getPropertiesFromMethods($model)
$begin = strpos($code, 'function(');
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);

$customPivots = [];

foreach (
$this->getRelationTypes() as $relation => $impl
) {
Expand Down Expand Up @@ -716,20 +718,11 @@ public function getPropertiesFromMethods($model)
if (!in_array($pivot, [Pivot::class, MorphPivot::class])) {
$pivot = $this->getClassNameInDestinationFile($model, $pivot);

if ($existingPivot = ($this->properties[$relationObj->getPivotAccessor()] ?? null)) {
// If the pivot is already set, we need to append the type to it
$pivot .= '|' . $existingPivot['type'];
if(isset($customPivots[$relationObj->getPivotAccessor()])){
$customPivots[$relationObj->getPivotAccessor()][] = $pivot;
} else {
// pivots are not always set
$pivot .= '|null';
$customPivots[$relationObj->getPivotAccessor()] = [$pivot];
}

$this->setProperty(
$relationObj->getPivotAccessor(),
$this->getClassNameInDestinationFile($model, $pivot),
true,
false
);
}
}

Expand Down Expand Up @@ -787,6 +780,15 @@ public function getPropertiesFromMethods($model)
}
}
}

foreach($customPivots as $pivotAccessor => $pivots){
$this->setProperty(
$pivotAccessor,
implode('|', $pivots) . '|null',
true,
false,
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
/**
*
*
* @property-read \DifferentCustomPivot|\CustomPivot|null $pivot
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationCustomPivotUsingSameAccessor
* @property-read int|null $relation_custom_pivot_using_same_accessor_count
* @property-read \CustomPivot|null $customAccessor
* @property-read DifferentCustomPivot|null $pivot
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithCustomPivot
* @property-read int|null $relation_with_custom_pivot_count
* @property-read \DifferentCustomPivot|null $differentCustomAccessor
* @property-read CustomPivot|null $customAccessor
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithDifferentCustomPivot
* @property-read int|null $relation_with_different_custom_pivot_count
* @property-read DifferentCustomPivot|null $differentCustomAccessor
* @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithDifferentCustomPivotUsingSameAccessor
* @property-read int|null $relation_with_different_custom_pivot_using_same_accessor_count
* @method static \Illuminate\Database\Eloquent\Builder<static>|ModelWithPivot newModelQuery()
Expand Down

0 comments on commit 37559ab

Please # to comment.