普通网友
2014-09-01 20:00
浏览 15
已采纳

Laravel - 相同的模型通过另一个相关

I'm having trouble finding the appropriate documentation on this.

I'm have a User model, each User can have a many to many relationship with a Site. I am trying to find out how to get the relationships between Users.

For example, one User might be the Site owner, and the other could be the Client. If I have the owner object, how can I retrieve an array of Clients, associated with all, or individual Sites.

I've tried using

public function clients() {
    return $this->hasManyThrough('User', 'Site');
}

However this still returns the current user which I'm unable to filter out.

I'm not sure if I have my models wrong, e.g. needing to have an Owner and a Client model, which both extend a generic User.

Any help would be appreciated.

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我在找到相应的文档时遇到了麻烦。

I 我有一个 User 模型,每个 User 可以与 Site 有多对多的关系。 我试图找出如何获取 User 之间的关系。

例如,一个 User 可能是站点所有者,另一个可能是 Client 。 如果我拥有所有者对象,我该如何检索与所有或单个 Site 相关联的 Client 数组。

我尝试使用

 公共功能客户端(){
返回$ this-> hasManyThrough('用户','网站'); 
} 
    
 
 

然而,这仍然会返回我无法过滤掉的当前用户。

我不确定我是否有 我的模型错了,例如 需要拥有一个所有者和一个客户模型,它们都扩展了一般用户。

任何帮助都将不胜感激。

谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题