@@ -83,6 +83,32 @@ protected function newHasMany(Builder $query, Model $parent, $foreignKey, $local
8383 return new HasMany ($ query , $ parent , $ foreignKey , $ localKey );
8484 }
8585
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+
86112 /**
87113 * Instantiate a new HasOne relationship.
88114 *
0 commit comments