Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

Hi! This is what I'll do, I'll create three models. Blog, Post (I like to call it as post instead of page) and Comment. Then I'll create one-to-many relationships.

Blog one-to-many Post
Post one-to-many Comment

In your comments table you could just add likes and reply_id field.

I hope this helps.

Last updated 1 year ago.
0

sherwinncnadev said:

Hi! This is what I'll do, I'll create three models. Blog, Post (I like to call it as post instead of page) and Comment. Then I'll create one-to-many relationships.

Blog one-to-many Post
Post one-to-many Comment

In your comments table you could just add likes and reply_id field.

I hope this helps.

Hello, thank you for your reply.

This is how I actually implemented it and it works perfectly. However, if I want to format the comments in the HTML, I need to have it chunked by replies. Because, when a comment is a reply to another comment, the reply should be displayed under the "main" comment. How would you be doing this?

I hope this makes sense.

Last updated 1 year ago.
0

The first solution that popped in my head is you could create a recursive function that accepts an eloquent collection of comments and what it'll do is loop through it all and check if a comment has a reply. If it has a reply call the function again. I suggest you should do a paging for comments since this approach will slow your website if it's handling a lot of comments.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.