Retrieving all morphedByMany relations in Laravel Eloquent

后端 未结 3 1267
半阙折子戏
半阙折子戏 2020-12-31 01:01

In the Laravel documentation, there is the following example for retrieving morphedByMany relations, which are many-to-many polymorphic relations.

Larav

3条回答
  •  独厮守ぢ
    2020-12-31 01:51

    You should be able to add a relationship on your Tag class as such

    public function taggable()
    {
        return $this->morphedTo();
    }
    

    That will use the taggable_id and taggable_type to get the relevant Model that it is tied to.

提交回复
热议问题