@@ -153,9 +153,13 @@ public function hasOneThrough($related, $through, $firstKey = null, $secondKey =
153
153
$ secondKey = $ secondKey ?: $ through ->getForeignKey ();
154
154
155
155
return $ this ->newHasOneThrough (
156
- $ this ->newRelatedInstance ($ related )->newQuery (), $ this , $ through ,
157
- $ firstKey , $ secondKey , $ localKey ?: $ this ->getKeyName (),
158
- $ secondLocalKey ?: $ through ->getKeyName ()
156
+ $ this ->newRelatedInstance ($ related )->newQuery (),
157
+ $ this ,
158
+ $ through ,
159
+ $ firstKey ,
160
+ $ secondKey ,
161
+ $ localKey ?: $ this ->getKeyName (),
162
+ $ secondLocalKey ?: $ through ->getKeyName (),
159
163
);
160
164
}
161
165
@@ -562,9 +566,15 @@ protected function newMorphMany(Builder $query, Model $parent, $type, $id, $loca
562
566
* @param string|null $relation
563
567
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, $this>
564
568
*/
565
- public function belongsToMany ($ related , $ table = null , $ foreignPivotKey = null , $ relatedPivotKey = null ,
566
- $ parentKey = null , $ relatedKey = null , $ relation = null )
567
- {
569
+ public function belongsToMany (
570
+ $ related ,
571
+ $ table = null ,
572
+ $ foreignPivotKey = null ,
573
+ $ relatedPivotKey = null ,
574
+ $ parentKey = null ,
575
+ $ relatedKey = null ,
576
+ $ relation = null ,
577
+ ) {
568
578
// If no relationship name was passed, we will pull backtraces to get the
569
579
// name of the calling function. We will use that function name as the
570
580
// title of this relation since that is a great convention to apply.
@@ -589,9 +599,14 @@ public function belongsToMany($related, $table = null, $foreignPivotKey = null,
589
599
}
590
600
591
601
return $ this ->newBelongsToMany (
592
- $ instance ->newQuery (), $ this , $ table , $ foreignPivotKey ,
593
- $ relatedPivotKey , $ parentKey ?: $ this ->getKeyName (),
594
- $ relatedKey ?: $ instance ->getKeyName (), $ relation
602
+ $ instance ->newQuery (),
603
+ $ this ,
604
+ $ table ,
605
+ $ foreignPivotKey ,
606
+ $ relatedPivotKey ,
607
+ $ parentKey ?: $ this ->getKeyName (),
608
+ $ relatedKey ?: $ instance ->getKeyName (),
609
+ $ relation ,
595
610
);
596
611
}
597
612
@@ -611,9 +626,16 @@ public function belongsToMany($related, $table = null, $foreignPivotKey = null,
611
626
* @param string|null $relationName
612
627
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, TDeclaringModel>
613
628
*/
614
- protected function newBelongsToMany (Builder $ query , Model $ parent , $ table , $ foreignPivotKey , $ relatedPivotKey ,
615
- $ parentKey , $ relatedKey , $ relationName = null )
616
- {
629
+ protected function newBelongsToMany (
630
+ Builder $ query ,
631
+ Model $ parent ,
632
+ $ table ,
633
+ $ foreignPivotKey ,
634
+ $ relatedPivotKey ,
635
+ $ parentKey ,
636
+ $ relatedKey ,
637
+ $ relationName = null ,
638
+ ) {
617
639
return new BelongsToMany ($ query , $ parent , $ table , $ foreignPivotKey , $ relatedPivotKey , $ parentKey , $ relatedKey , $ relationName );
618
640
}
619
641
@@ -633,10 +655,17 @@ protected function newBelongsToMany(Builder $query, Model $parent, $table, $fore
633
655
* @param bool $inverse
634
656
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany<TRelatedModel, $this>
635
657
*/
636
- public function morphToMany ($ related , $ name , $ table = null , $ foreignPivotKey = null ,
637
- $ relatedPivotKey = null , $ parentKey = null ,
638
- $ relatedKey = null , $ relation = null , $ inverse = false )
639
- {
658
+ public function morphToMany (
659
+ $ related ,
660
+ $ name ,
661
+ $ table = null ,
662
+ $ foreignPivotKey = null ,
663
+ $ relatedPivotKey = null ,
664
+ $ parentKey = null ,
665
+ $ relatedKey = null ,
666
+ $ relation = null ,
667
+ $ inverse = false ,
668
+ ) {
640
669
$ relation = $ relation ?: $ this ->guessBelongsToManyRelation ();
641
670
642
671
// First, we will need to determine the foreign key and "other key" for the
@@ -660,9 +689,16 @@ public function morphToMany($related, $name, $table = null, $foreignPivotKey = n
660
689
}
661
690
662
691
return $ this ->newMorphToMany (
663
- $ instance ->newQuery (), $ this , $ name , $ table ,
664
- $ foreignPivotKey , $ relatedPivotKey , $ parentKey ?: $ this ->getKeyName (),
665
- $ relatedKey ?: $ instance ->getKeyName (), $ relation , $ inverse
692
+ $ instance ->newQuery (),
693
+ $ this ,
694
+ $ name ,
695
+ $ table ,
696
+ $ foreignPivotKey ,
697
+ $ relatedPivotKey ,
698
+ $ parentKey ?: $ this ->getKeyName (),
699
+ $ relatedKey ?: $ instance ->getKeyName (),
700
+ $ relation ,
701
+ $ inverse ,
666
702
);
667
703
}
668
704
@@ -684,12 +720,30 @@ public function morphToMany($related, $name, $table = null, $foreignPivotKey = n
684
720
* @param bool $inverse
685
721
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany<TRelatedModel, TDeclaringModel>
686
722
*/
687
- protected function newMorphToMany (Builder $ query , Model $ parent , $ name , $ table , $ foreignPivotKey ,
688
- $ relatedPivotKey , $ parentKey , $ relatedKey ,
689
- $ relationName = null , $ inverse = false )
690
- {
691
- return new MorphToMany ($ query , $ parent , $ name , $ table , $ foreignPivotKey , $ relatedPivotKey , $ parentKey , $ relatedKey ,
692
- $ relationName , $ inverse );
723
+ protected function newMorphToMany (
724
+ Builder $ query ,
725
+ Model $ parent ,
726
+ $ name ,
727
+ $ table ,
728
+ $ foreignPivotKey ,
729
+ $ relatedPivotKey ,
730
+ $ parentKey ,
731
+ $ relatedKey ,
732
+ $ relationName = null ,
733
+ $ inverse = false ,
734
+ ) {
735
+ return new MorphToMany (
736
+ $ query ,
737
+ $ parent ,
738
+ $ name ,
739
+ $ table ,
740
+ $ foreignPivotKey ,
741
+ $ relatedPivotKey ,
742
+ $ parentKey ,
743
+ $ relatedKey ,
744
+ $ relationName ,
745
+ $ inverse ,
746
+ );
693
747
}
694
748
695
749
/**
@@ -707,9 +761,16 @@ protected function newMorphToMany(Builder $query, Model $parent, $name, $table,
707
761
* @param string|null $relation
708
762
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany<TRelatedModel, $this>
709
763
*/
710
- public function morphedByMany ($ related , $ name , $ table = null , $ foreignPivotKey = null ,
711
- $ relatedPivotKey = null , $ parentKey = null , $ relatedKey = null , $ relation = null )
712
- {
764
+ public function morphedByMany (
765
+ $ related ,
766
+ $ name ,
767
+ $ table = null ,
768
+ $ foreignPivotKey = null ,
769
+ $ relatedPivotKey = null ,
770
+ $ parentKey = null ,
771
+ $ relatedKey = null ,
772
+ $ relation = null ,
773
+ ) {
713
774
$ foreignPivotKey = $ foreignPivotKey ?: $ this ->getForeignKey ();
714
775
715
776
// For the inverse of the polymorphic many-to-many relations, we will change
@@ -718,8 +779,15 @@ public function morphedByMany($related, $name, $table = null, $foreignPivotKey =
718
779
$ relatedPivotKey = $ relatedPivotKey ?: $ name .'_id ' ;
719
780
720
781
return $ this ->morphToMany (
721
- $ related , $ name , $ table , $ foreignPivotKey ,
722
- $ relatedPivotKey , $ parentKey , $ relatedKey , $ relation , true
782
+ $ related ,
783
+ $ name ,
784
+ $ table ,
785
+ $ foreignPivotKey ,
786
+ $ relatedPivotKey ,
787
+ $ parentKey ,
788
+ $ relatedKey ,
789
+ $ relation ,
790
+ true ,
723
791
);
724
792
}
725
793
0 commit comments