@@ -83,6 +83,32 @@ protected function newHasMany(Builder $query, Model $parent, $foreignKey, $local
83
83
return new HasMany ($ query , $ parent , $ foreignKey , $ localKey );
84
84
}
85
85
86
+ /**
87
+ * Define a polymorphic one-to-many relationship.
88
+ *
89
+ * @param string $related
90
+ * @param string $name
91
+ * @param string|null $type
92
+ * @param string|null $id
93
+ * @param string|null $localKey
94
+ * @return \Illuminate\Database\Eloquent\Relations\MorphMany
95
+ */
96
+ public function morphMany ($ related , $ name , $ type = null , $ id = null , $ localKey = null )
97
+ {
98
+ $ instance = $ this ->newRelatedInstance ($ related );
99
+
100
+ // Here we will gather up the morph type and ID for the relationship so that we
101
+ // can properly query the intermediate table of a relation. Finally, we will
102
+ // get the table and create the relationship instances for the developers.
103
+ [$ type , $ id ] = $ this ->getMorphs ($ name , $ type , $ id );
104
+
105
+ $ table = $ instance ->getTable ();
106
+
107
+ $ localKey = $ localKey ?: $ this ->getKeyName ();
108
+
109
+ return $ this ->newMorphMany ($ instance ->newQuery (), $ this , $ type , $ id , $ localKey );
110
+ }
111
+
86
112
/**
87
113
* Instantiate a new HasOne relationship.
88
114
*
0 commit comments