简体   繁体   English

laravel 3向枢轴

[英]laravel 3 way pivot

I've one many to many relationship between Entities and Affiliated Tables, basically an affiliated can attend to many entities(example, medical services, dentist offices). 我在实体和附属表之间存在一对多关系,基本上附属机构可以参加许多实体(例如,医疗服务,牙医诊所)。 One Entity can be visited by one or many affiliated. 一个或多个实体可以访问一个实体。 Additionaly , one or more benefits can be occupied by one affiliated in a particular entity. 另外,附属于特定实体的一个或多个利益可以被占有。 As shown in the image. 如图所示。 在此处输入图片说明

I want to be able to answer queries like, which benefits where used by the affiliated in a particular entity. 我希望能够回答类似的查询,这在特定实体中的关联机构在使用时会有所帮助。

Should i create a new Model, how should i rewrite the many-to-many relationship for ORM. 我应该创建一个新模型,如何为ORM重写多对多关系。

Thanks in advance! 提前致谢!

Don't need a Affiliated_has_Entities model. 不需要Affiliated_has_Entities模型。 You could write the relationships as below, remember to check for arguments and its order in the belognsToMany relationship (sorry for misspelled words) 您可以按照以下方式编写关系,记住要在belognsToMany关系中检查参数及其顺序( belognsToMany拼写的单词表示抱歉)

Entities model 实体模型

public function afilliateds(){
return $this->belongsToMany('Afilliated', 'Afilliated_has_Entities');
}

Afilliated model 充实模型

public function entities(){
return $this->belongsToMany('Entities', 'Afilliated_has_Entities');
}

public function benefits(){
return $this->belongsToMany('Entities', 'Afilliated_has_Entities');
}

Benefits model 利益模式

public function entites(){
return $this->belongsToMany('Entities', 'Afilliated_has_Entities');
}

And so on.. 等等..

I hope it helps 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM