【发布时间】:2018-01-10 12:27:58
【问题描述】:
用户可以在帖子中附加文件:图片或视频。
数据库结构如下:
posts
id
images
id
videos
id
post_attachment
post_id
attachment_id (id from images or videos table)
attachment_type ('image' or 'video')
困难在于,根据附件的类型,我们应该参考不同的表格。
我应该将 laravel 函数的什么关系应用于Post 模型以通过post_attachment 表获取所有附件?
我认为这种关系是来自一系列的变形,但我无法准确理解是哪一个。
class Post {
public function attachments () {
return $this->morph?????
}
}
请帮我写出这个案例的正确关系。
【问题讨论】: