jeudi 22 septembre 2016

Create a list of nested comments

I'm creating a nested comment system, much like Disqus:

http://ift.tt/2crsOAF (example of nested comments)

I've set up my comments table with the following format:

| id | user_id | post_id | parent_id | text |

Where parent_id is the parent comment id.

This is where I get stuck. I added the following relationship to my Comments.php model:

public function parent()
{
    return $this->hasOne('App\Comment', 'id', 'parent_id');
}

But I'm not sure how to continue from here.

I have a comment.blade.php layout (cut down for simplicity):

<div class="comment">
    <div class="text"></div>
    <div class="nested-comments">ALL NESTED COMMENTS SHOULD GO HERE</div>
</div>

How can I query the database and then display the comments in a nested format, like in the image above?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire