@@ -549,15 +549,18 @@ public static function with($relations)
549
549
*
550
550
* @param string $related
551
551
* @param string $foreignKey
552
+ * @param string $localKey
552
553
* @return \Illuminate\Database\Eloquent\Relations\HasOne
553
554
*/
554
- public function hasOne ($ related , $ foreignKey = null )
555
+ public function hasOne ($ related , $ foreignKey = null , $ localKey = null )
555
556
{
556
557
$ foreignKey = $ foreignKey ?: $ this ->getForeignKey ();
557
558
558
559
$ instance = new $ related ;
559
560
560
- return new HasOne ($ instance ->newQuery (), $ this , $ instance ->getTable ().'. ' .$ foreignKey );
561
+ $ localKey = $ localKey ?: $ this ->getKeyName ();
562
+
563
+ return new HasOne ($ instance ->newQuery (), $ this , $ instance ->getTable ().'. ' .$ foreignKey , $ localKey );
561
564
}
562
565
563
566
/**
@@ -569,15 +572,17 @@ public function hasOne($related, $foreignKey = null)
569
572
* @param string $id
570
573
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
571
574
*/
572
- public function morphOne ($ related , $ name , $ type = null , $ id = null )
575
+ public function morphOne ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
573
576
{
574
577
$ instance = new $ related ;
575
578
576
579
list ($ type , $ id ) = $ this ->getMorphs ($ name , $ type , $ id );
577
580
578
581
$ table = $ instance ->getTable ();
579
582
580
- return new MorphOne ($ instance ->newQuery (), $ this , $ table .'. ' .$ type , $ table .'. ' .$ id );
583
+ $ localKey = $ localKey ?: $ this ->getKeyName ();
584
+
585
+ return new MorphOne ($ instance ->newQuery (), $ this , $ table .'. ' .$ type , $ table .'. ' .$ id , $ localKey );
581
586
}
582
587
583
588
/**
@@ -649,15 +654,18 @@ public function morphTo($name = null, $type = null, $id = null)
649
654
*
650
655
* @param string $related
651
656
* @param string $foreignKey
657
+ * @param string $localKey
652
658
* @return \Illuminate\Database\Eloquent\Relations\HasMany
653
659
*/
654
- public function hasMany ($ related , $ foreignKey = null )
660
+ public function hasMany ($ related , $ foreignKey = null , $ localKey = null )
655
661
{
656
662
$ foreignKey = $ foreignKey ?: $ this ->getForeignKey ();
657
663
658
664
$ instance = new $ related ;
659
665
660
- return new HasMany ($ instance ->newQuery (), $ this , $ instance ->getTable ().'. ' .$ foreignKey );
666
+ $ localKey = $ localKey ?: $ this ->getKeyName ();
667
+
668
+ return new HasMany ($ instance ->newQuery (), $ this , $ instance ->getTable ().'. ' .$ foreignKey , $ localKey );
661
669
}
662
670
663
671
/**
@@ -687,9 +695,10 @@ public function hasManyThrough($related, $through, $firstKey = null, $secondKey
687
695
* @param string $name
688
696
* @param string $type
689
697
* @param string $id
698
+ * @param string $localKey
690
699
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
691
700
*/
692
- public function morphMany ($ related , $ name , $ type = null , $ id = null )
701
+ public function morphMany ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
693
702
{
694
703
$ instance = new $ related ;
695
704
@@ -700,7 +709,9 @@ public function morphMany($related, $name, $type = null, $id = null)
700
709
701
710
$ table = $ instance ->getTable ();
702
711
703
- return new MorphMany ($ instance ->newQuery (), $ this , $ table .'. ' .$ type , $ table .'. ' .$ id );
712
+ $ localKey = $ localKey ?: $ this ->getKeyName ();
713
+
714
+ return new MorphMany ($ instance ->newQuery (), $ this , $ table .'. ' .$ type , $ table .'. ' .$ id , $ localKey );
704
715
}
705
716
706
717
/**
0 commit comments