【发布时间】:2016-11-29 15:11:03
【问题描述】:
我需要从与 belongsToMany 的关系 belongsToMany 中获取数据,结果会是这样:我的模型中的 A->B->C 将是 providers->caption->eventType,所以你需要从一个事件类型。
模型看起来像:
提供者模型
Class Provider extends Model {
public function captions() {
return $this->belongsToMany(Caption::class);
}
}
字幕模型
Class Caption extend Model {
public function event_type() {
return $this->belongsToMany(Event_type::class);
}
public function providers() {
return $this->belongsToMany(Provider::class);
}
}
事件类型模型
Class Event_type extends Model {
public function captions() {
return $this->belongsToMany(Caption::class);
}
}
数据库如下:
供应商
身份证
名字
event_type
身份证
名字
字幕
身份证
名字
caption_event_type
caption_id
event_type_id
caption_provider
caption_id
provider_id
谢谢。
【问题讨论】:
-
请添加您的关系和/或模型,否则无法帮助您。
-
型号与合作伙伴 Saumya Rastogi 评论的型号相同,谢谢
标签: php laravel eloquent has-and-belongs-to-many