@@ -536,14 +536,18 @@ protected function newBelongsToMany(Builder $query, Model $parent, $table, $fore
536
536
* @param string|null $relatedPivotKey
537
537
* @param string|null $parentKey
538
538
* @param string|null $relatedKey
539
+ * @param string|null $relation
539
540
* @param bool $inverse
540
541
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
541
542
*/
542
543
public function morphToMany ($ related , $ name , $ table = null , $ foreignPivotKey = null ,
543
544
$ relatedPivotKey = null , $ parentKey = null ,
544
- $ relatedKey = null , $ inverse = false )
545
+ $ relatedKey = null , $ relation = null , $ inverse = false )
545
546
{
546
- $ caller = $ this ->guessBelongsToManyRelation ();
547
+ // If no relationship name was passed, we will pull backtraces to get the
548
+ // name of the calling function. We will use that function name as the
549
+ // title of this relation since that is a great convention to apply.
550
+ $ relation = $ relation ?: $ this ->guessBelongsToManyRelation ();
547
551
548
552
// First, we will need to determine the foreign key and "other key" for the
549
553
// relationship. Once we have determined the keys we will make the query
@@ -568,7 +572,7 @@ public function morphToMany($related, $name, $table = null, $foreignPivotKey = n
568
572
return $ this ->newMorphToMany (
569
573
$ instance ->newQuery (), $ this , $ name , $ table ,
570
574
$ foreignPivotKey , $ relatedPivotKey , $ parentKey ?: $ this ->getKeyName (),
571
- $ relatedKey ?: $ instance ->getKeyName (), $ caller , $ inverse
575
+ $ relatedKey ?: $ instance ->getKeyName (), $ relation , $ inverse
572
576
);
573
577
}
574
578
@@ -605,10 +609,11 @@ protected function newMorphToMany(Builder $query, Model $parent, $name, $table,
605
609
* @param string|null $relatedPivotKey
606
610
* @param string|null $parentKey
607
611
* @param string|null $relatedKey
612
+ * @param string|null $relation
608
613
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
609
614
*/
610
615
public function morphedByMany ($ related , $ name , $ table = null , $ foreignPivotKey = null ,
611
- $ relatedPivotKey = null , $ parentKey = null , $ relatedKey = null )
616
+ $ relatedPivotKey = null , $ parentKey = null , $ relatedKey = null , $ relation = null )
612
617
{
613
618
$ foreignPivotKey = $ foreignPivotKey ?: $ this ->getForeignKey ();
614
619
@@ -619,7 +624,7 @@ public function morphedByMany($related, $name, $table = null, $foreignPivotKey =
619
624
620
625
return $ this ->morphToMany (
621
626
$ related , $ name , $ table , $ foreignPivotKey ,
622
- $ relatedPivotKey , $ parentKey , $ relatedKey , true
627
+ $ relatedPivotKey , $ parentKey , $ relatedKey , $ relation , true
623
628
);
624
629
}
625
630
0 commit comments