- Laravel Version: 5.4.10
- PHP Version: 7.0.13
Description:
It is possible to load relations to models in a Collection but it seems not to be possible to load count relation on a Collection.
For example, if I have these classes
class Post extends Model {
public function tags() {
return $this->hasMany(Tag::class);
}
}
class Tag extends Model {
public function posts() {
return $this->hasMany(Post::class);
}
}
and assuming that $tags is a Collection of Tags, I can do $tags->load('posts') to load relation posts on every tag on $tags but I cannot do $tags->load('posts_count') to load posts_count.
Is there a way to do that ?