The requirements are like this,
I have user table and article table
user table structure
id
name
email
...
articleTable structure
id
title
content
...
The user table and article table will have the following relationship
1, Favorite
2, Like
3, Reply
4, Follow
Do I have to build 4 Models
article_user_collect
article_user_point
article_user_reply
article_user_attention
Each table only has user_id and article_id
The many-to-many relationship introduced in the laravel model is not suitable for this situation! ! !
Because this is not many-to-many.
It is still recommended to create four tables such as comments and favorites
Use a table to record the relationship between them
article_user
id (self-increment)
articleId
userId
type 1. Collection 2. Like 3. Reply 4. Follow
Like table:
likes
字段有user_id
存点赞的用户的id,article_id
存文章的id;评论表:
comments
字段有article_id
,user_id
, the same is true for collection table.