Skip to content

How to get nested relation count? #234

Closed Answered by staudenmeir
mansoorkhan96 asked this question in Q&A
Discussion options

You must be logged in to vote

This is a bigger topic:
The package can't fetch comments from multiple levels at once. Your allComments relationship can only return second-level comments and your approach with hasManyDeepFromRelations() is correct for this use case. The empty result is actually a bug that I just fixed.

You can use one of my other packages to get all comments with a single relationship that you can use with withCount():
https://github.com/staudenmeir/laravel-merged-relations

Update this package to get the bug fix, install the other package and set it up:

class Activity extends Model
{
    use \Staudenmeir\LaravelMergedRelations\Eloquent\HasMergedRelationships;
    use HasRelationships;

    public function 

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@mansoorkhan96
Comment options

@mansoorkhan96
Comment options

Comment options

You must be logged in to vote
3 replies
@mansoorkhan96
Comment options

@mansoorkhan96
Comment options

@mansoorkhan96
Comment options

Answer selected by staudenmeir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants