Php Laravel多对多多态查询返回NULL
我已经为此工作了几个小时,一个简单的问题都找不出答案。我似乎无法通过morphedByMany检索我的多态多对多。相关代码如下: 标记模型片段:Php Laravel多对多多态查询返回NULL,php,laravel,polymorphism,eloquent,Php,Laravel,Polymorphism,Eloquent,我已经为此工作了几个小时,一个简单的问题都找不出答案。我似乎无法通过morphedByMany检索我的多态多对多。相关代码如下: 标记模型片段: class Tag extends Eloquent { protected $table = 'tags'; public function posts() { return $this->morphedByMany('Post', 'taggable'); } class Post extends E
class Tag extends Eloquent
{
protected $table = 'tags';
public function posts()
{
return $this->morphedByMany('Post', 'taggable');
}
class Post extends Eloquent
{
protected $table = 'posts';
public $incrementing = false;
public function tags()
{
return $this->morphToMany('Tag', 'taggable');
}
发布模型片段:
class Tag extends Eloquent
{
protected $table = 'tags';
public function posts()
{
return $this->morphedByMany('Post', 'taggable');
}
class Post extends Eloquent
{
protected $table = 'posts';
public $incrementing = false;
public function tags()
{
return $this->morphToMany('Tag', 'taggable');
}
令人不快的路线。尽管在数据库中可以看到post和post的标签,但无论我如何调整,此行都返回NULL:
$posts = Tag::find(1)->posts;
模式(注意,我也尝试过这样做,但没有索引这些字段,也没有在tag_id上使用外键):
如果您需要任何其他代码,请告诉我。我已经筋疲力尽了。你试过
Tag::find(1)->posts()->get()了吗代码>?这将产生:调用undefined方法illumb\Database\Query\Builder::posts()噢,哇,我发现我复制并粘贴了一些模型文本,这导致我的标志模型也被称为标记。鉴于Flag.php是按字母顺序排列的第一个,我假设它是首先引用的,并且没有多态关系。令人尴尬的现在删除这个是不是很有礼貌,因为它可能没有多大帮助哈哈?