请问使用 laravel 的多对多的多态关联父表主键必须是叫做'id'吗?

2017-03-24 13:47:38 +08:00
 xx19941215

我叫做 eid 好像不好使啊。 是用在 product 和 tag 这两个实体之间。 这是定义在 product 模型上的

public function tags()
{
	return $this->morphToMany(Tag::class, 'taggable');
}

相关表结构

2325 次点击
所在节点    PHP
2 条回复
sobigfish
2017-03-24 14:15:10 +08:00
https://laravel.com/api/5.4/Illuminate/Database/Eloquent/Concerns/HasRelationships.html#method_morphToMany
MorphToMany morphToMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null, bool $inverse = false)
xx19941215
2017-03-24 14:36:16 +08:00
@sobigfish 好像不太对啊,这里是第几个值来设置父表的键?我试了$foreignKey 不太对啊啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/350018

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX