【发布时间】:2016-03-11 19:13:02
【问题描述】:
在 Laravel 文档中,有以下示例用于检索 morphedByMany 关系,这是多对多的多态关系。
Laravel Many to Many polymorphic relations documentation
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
/**
* Get all of the posts that are assigned this tag.
*/
public function posts()
{
return $this->morphedByMany('App\Post', 'taggable');
}
/**
* Get all of the videos that are assigned this tag.
*/
public function videos()
{
return $this->morphedByMany('App\Video', 'taggable');
}
}
如何在一个查询/集合中获得所有morphed 关系的列表,例如posts 和videos,然后如果我后来添加photos(或其他任何东西),那也是?
【问题讨论】:
-
找到解决方案了吗?
-
我做了,但我没有代码,这是一份旧工作……我所做的基本上是使用查询生成器来获取结果并使用自定义集合中的数据构建模型类。
标签: php laravel eloquent polymorphism