Ozan
176
5
General

Polymorphic Relationships Customized Eager Loading

Posted 4 years ago by Ozan

I have a Post model related with Like model with the morphTo() relationship.

I only want to get the counts of likes for a post but this gives me the same result.

return Post::with(['owner', 'tags', 'likes' => function($query)
        {
            $query->count();
        }])->where('slug', $slug)->first();

What should I do?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.