mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
feat(pivot): add support for multiple pivot types when using the same accessor (#1597)
* feat(pivot): add support for multiple pivot types when using the same accessor
* composer fix-style
* changelog
* resolve namespaces
* Revert "resolve namespaces"
This reverts commit 37559ab089.
* resolve namespaces
---------
Co-authored-by: laravel-ide-helper <[email protected]>
This commit is contained in:
co-authored by
laravel-ide-helper
parent
4b051e45c7
commit
dc70337e48
@@ -714,14 +714,25 @@ class ModelsCommand extends Command
|
||||
if ($relationObj instanceof BelongsToMany) {
|
||||
$pivot = get_class($relationObj->newPivot());
|
||||
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'];
|
||||
} else {
|
||||
// pivots are not always set
|
||||
$pivot .= '|null';
|
||||
}
|
||||
|
||||
$this->setProperty(
|
||||
$relationObj->getPivotAccessor(),
|
||||
$this->getClassNameInDestinationFile($model, $pivot),
|
||||
$pivot,
|
||||
true,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Collection or array of models (because Collection is Arrayable)
|
||||
$relatedClass = '\\' . get_class($relationObj->getRelated());
|
||||
$collectionClass = $this->getCollectionClass($relatedClass);
|
||||
|
||||
Reference in New Issue
Block a user