File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
tests/Console/ModelsCommand/Pivot Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -729,8 +729,13 @@ public function getPropertiesFromMethods($model)
729729 $ pivot = $ this ->getClassNameInDestinationFile ($ model , $ pivot );
730730
731731 if ($ existingPivot = ($ this ->properties [$ relationObj ->getPivotAccessor ()] ?? null )) {
732- // If the pivot is already set, we need to append the type to it
733- $ pivot .= '| ' . $ existingPivot ['type ' ];
732+ if (!str_contains ($ existingPivot ['type ' ], $ pivot . '| ' )) {
733+ // If the pivot is already set, we need to append the type to it
734+ $ pivot .= '| ' . $ existingPivot ['type ' ];
735+ } else {
736+ // this class is already set
737+ $ pivot = $ existingPivot ['type ' ];
738+ }
734739 } else {
735740 // pivots are not always set
736741 $ pivot .= '|null ' ;
Original file line number Diff line number Diff line change @@ -33,6 +33,12 @@ public function relationCustomPivotUsingSameAccessor()
3333 ->using (CustomPivot::class);
3434 }
3535
36+ public function relationCustomPivotUsingSameAccessorAndClass ()
37+ {
38+ return $ this ->belongsToMany (ModelwithPivot::class)
39+ ->using (CustomPivot::class);
40+ }
41+
3642 public function relationWithDifferentCustomPivotUsingSameAccessor ()
3743 {
3844 return $ this ->belongsToMany (ModelwithPivot::class)
Original file line number Diff line number Diff line change 1414 * @property-read DifferentCustomPivot|CustomPivot|null $pivot
1515 * @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationCustomPivotUsingSameAccessor
1616 * @property-read int|null $relation_custom_pivot_using_same_accessor_count
17+ * @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationCustomPivotUsingSameAccessorAndClass
18+ * @property-read int|null $relation_custom_pivot_using_same_accessor_and_class_count
1719 * @property-read CustomPivot|null $customAccessor
1820 * @property-read \Illuminate\Database\Eloquent\Collection<int, ModelWithPivot> $relationWithCustomPivot
1921 * @property-read int|null $relation_with_custom_pivot_count
@@ -52,6 +54,12 @@ public function relationCustomPivotUsingSameAccessor()
5254 ->using (CustomPivot::class);
5355 }
5456
57+ public function relationCustomPivotUsingSameAccessorAndClass ()
58+ {
59+ return $ this ->belongsToMany (ModelwithPivot::class)
60+ ->using (CustomPivot::class);
61+ }
62+
5563 public function relationWithDifferentCustomPivotUsingSameAccessor ()
5664 {
5765 return $ this ->belongsToMany (ModelwithPivot::class)
You can’t perform that action at this time.
0 commit comments