Infinite relationship ...? [closed]

2

I have a doubt that would be, how to conduct a relationship that can be infinite: Ex:

User table with the user id field that would be one for many with Post Table.

Inside the Post Table would have post_id that would have more post inside it.

Post table with fields (User_id, Post_id, Text). Post2 table with fields (User_id, Post2_id, Post2_postID, Text).

In the scenario above if there were 10 more post would use 10 more post tables.

There is some way to have such relationships.

With comparative would be a tree of directories that within each one can have as many directories as you want and files.

    
asked by anonymous 13.12.2018 / 18:57

1 answer

1

You just need to have a table named post :

id
post_id
user_id
text

When a certain post does not have another post inside it, you should set post_id to NULL .

In your model, enter the following relationships:

public function posts()
{
    return $this->hasMany(Post::class);
}

public function todosOsPosts()
{
    return $this->posts()->with('todosOsPosts');
}

Ref: link

    
13.12.2018 / 22:22