I'm using laravel and i am trying to create my database with Users, this user will have many comments and many posts, the catch is that the post also need to have many comments that all will belong to a post. And that the comments from the user will belong to a post.
Maybe im thinking about it in the wrong way, but cant figure it out.
Help is apriciated
CodePudding user response:
A comment can belongTo both a Post and a Comment. So, a solution could look something like this:
Relationships
User
hasManyPosthasManyComment
Post
belongsToUserhasManyComment
Comment
belongToUserbelongsToPost
Models
| User |
|---|
| id |
| Post |
|---|
| id |
| user_id |
| Comment |
|---|
| id |
| user_id |
| post_id |

