mercredi 23 septembre 2015

How to count element from belogsToMany relation [Laravel 5]

Here is my relation:

public function commentsCount(){
    return $this->belongsToMany('App\Comment','project_comment');
}

I am trying to get acount of all comments...

Here is my query

 $count = Project::with(['commentsCount' => function($q) {
                    $q->where('project_id', $this->id);
            }, 'groups' => function($q) {
                $q->where('project_id', $this->id)->where('user_id', Auth::id());
            }])->where('id', $this->id)->get();

Any solution?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire