Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 11, 2020

Conversation

gdebrauwer
Copy link
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
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