Laravel में morphedByMany() का उपयोग Many to Many Polymorphic relation के लिये किया जाता हैं |
Example : एक Post model और एक Video Model एक अन्य Tag model को साझा कर सकते हैं |
इसका Table Structure निम्न प्रकार का होगा |
postsid - integername - stringvideosid - integername - stringtagsid - integername - stringtaggablestag_id - integertaggable_id - integertaggable_type - string
इसका Model Structure निम्न प्रकार का होगा
Post और Video Model मैं Tag Method को morphToMany मेथड की सहायता से बनाया जाता हैं
Controller : $campaign->posts()->sync($posts);
Model : public function posts()
{
return $this->morphedByMany(Post::class, 'relatable', 'tbl_s_relatable', 'fk_s_id', 'relatable_id');
}
No comments:
Post a Comment