我有以下问题, 我有四个型号: MainArea | Institute | institute_level |学生如下:
class MainArea extends Model
{
public function institute(){
return $this->belongsTo('\App\Institute');
}
public function places(){
return $this->hasMany('\App\Place');
}
}
class Institute extends Model
{
public function insLevel(){
return $this->hasMany('\App\InstituteLevel');
}
}
class InstituteLevel extends Model
{
public function students(){
return $this->hasMany('\App\Student','applying_level');
}
}
class Student extends Model
{
public function instituteLevel(){
return $this->belongsTo('\App\InstituteLevel','institute_level_id');
}
public function place(){
return $this->belongsTo('\App\Place');
}
}
现在,我希望在同一个机构中获得所有在其中注册的学生数量的区域?它应该是这样的。
$areas=\App\MainArea::withCount('institute.insLevel.students')->where('institute_id',$id)->get();
有什么建议吗?
答案 0 :(得分:1)
不幸的是,“withCount()”不支持Laravel 5.2中的嵌套关系。
Here's the comment from the contributor in a Github Pull Request.