Skip to content

[7.x] Add 'morphWithCount' method#32738

Merged
taylorotwell merged 1 commit into
laravel:7.xfrom
gdebrauwer:morph-with-count
May 11, 2020
Merged

[7.x] Add 'morphWithCount' method#32738
taylorotwell merged 1 commit into
laravel:7.xfrom
gdebrauwer:morph-with-count

Conversation

@gdebrauwer

Copy link
Copy Markdown
Contributor

The morphWith method was added by PR #28647. It allows you to eager load relations on morphed models.

This PR adds a morphWithCount method that allows you to eager load relationship counts on morphed models. It uses the same syntax as the morphWith method.

An example:

Comment::query()
    ->with(['commentable' => function (MorphTo $morphTo) {
        $morphTo->morphWithCount([Post::class => ['likes']]);
    }])
    ->get();

@taylorotwell
taylorotwell merged commit 2d0ec75 into laravel:7.x May 11, 2020
@taylorotwell

Copy link
Copy Markdown
Member

Would you mind sending in a documentation PR for this? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants