繁体   English   中英

Laravel雄辩的hasmany的hasmany

[英]Laravel eloquent has hasmany of hasmany

如何显示所有有照片附件的公司?

公司:

id | name 

用户:

id | name | company_id

职位:

id | user_id | text

post_attachment:

id | post_id | path | type

公司型号:

public function users() {
  return $this->hasMany('App\User')->orderBy('id', 'ASC');
}

用户模型:

public function posts() {
  return $this->hasMany('App\Post');
}

帖子模型:

public function images(){
  return $this->hasMany('App\PostsAttachment')->where("type", "image");
}

我想获得所有拥有用户的公司,这些用户的帖子至少包含2张图片。 有人可以帮助我吗?

我尝试了Company::has('users.posts.images', '<', 2)->get(); 但同时也会为用户形象低于2的公司提供服务。

用口才,你可以写你的逻辑为

$companies = Company::has('users.posts.images')->get();

请参阅查询关系存在

暂无
暂无

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

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