Support the ongoing development of Laravel.io →
Database Eloquent

How can I take all user post comments?

I'm already using morphTo() method between comments and posts/profiles to have all comments i one db table.

I tried to use hasMany('Comment', 'author_id') method but i can't get only post comments with post title, id, slug.

I need to have something like that:


Post Title | Comment date

Bla bla bla... | Yesterday, 12:00

Last updated 2 years ago.
0

Anybody?

Last updated 2 years ago.
0

Maybe has many through relationships (users comment through posts) can help.

Last updated 2 years ago.
0

Load all author/s, their posts and the comments on a post $authors = Author::with('posts.comments')->get();

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Delavor delavor Joined 15 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.