vendredi 24 juin 2016

Laravel5.2 with count

I have the following problem, I have four models: MainArea |Institute|institute_level|students with the following reations:

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');
}
}

Now, I want to get all areas with the count of students registered in it, in the same institute? it should be something like this.

        $areas=\App\MainArea::withCount('institute.insLevel.students')->where('institute_id',$id)->get();

Any suggestions ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28RyWAm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire