laravel - Two models or tables produce multiple relationships. How to model
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 16:51:06
0
3
404

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! ! !

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
小葫芦

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_iduser_id, the same is true for collection table.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!