Reputation: 68
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
Upvotes: 1
Views: 381
Reputation: 14740
A comment can belongTo
both a Post
and a Comment
. So, a solution could look something like this:
hasMany
PosthasMany
CommentbelongsTo
UserhasMany
CommentbelongTo
UserbelongsTo
PostUser |
---|
id |
Post |
---|
id |
user_id |
Comment |
---|
id |
user_id |
post_id |
Upvotes: 1