Php 使用Laravel的复杂评论、标记、投票、收藏夹数据库关系
我试图通过在Laravel4.2中构建一个小而复杂的应用程序来学习HABTM和多态关系。它接收链接,让用户通过标签、评论、投票、收藏和关注等关键词和内容以及彼此进行交互。老实说,我已经在这方面工作了大约3天,感觉自己就像是在泥地里打转。这是故障- 型号:Php 使用Laravel的复杂评论、标记、投票、收藏夹数据库关系,php,mysql,laravel,polymorphism,has-and-belongs-to-many,Php,Mysql,Laravel,Polymorphism,Has And Belongs To Many,我试图通过在Laravel4.2中构建一个小而复杂的应用程序来学习HABTM和多态关系。它接收链接,让用户通过标签、评论、投票、收藏和关注等关键词和内容以及彼此进行交互。老实说,我已经在这方面工作了大约3天,感觉自己就像是在泥地里打转。这是故障- 型号: User, Link, Tag, Comment, Vote, Favorite, Follow 超级基本用例: USER -> ACTION -> TARGET User -> Submit -> Link,
User, Link, Tag, Comment, Vote, Favorite, Follow
超级基本用例:
USER -> ACTION -> TARGET
User -> Submit -> Link, Tag, Comment
User -> Tag -> User, Link
User -> Comment -> User, Link
User -> Vote -> Tag, Comment
User -> Favorite -> User, Link, Tag, Comment
User -> Follow -> User, Tag
(假定)表格:
从这里。。我不确定我是否做对了。我一直在用不同的方式来定义一种关系,我只是想完全理解这种设计
我的模型文件看起来像什么?我可能会使用什么样的情况下belongtomany vs morphToMany?这是正确的方法还是我应该使用透视表进行探索?我希望能得到一些关于我需要学习什么才能正确实现这一点的建议
下面是我的User.php可能会是什么样子,但我不确定返回值应该是什么,因为我不太了解关系的需求
(假定)User.php
我觉得我就快成功了。我已经准备好了视图和路线,因为我已经重建了这个项目大约四次。我只需要努力解决所有这些数据库关系逻辑,这样我就可以让应用程序变得栩栩如生。非常感谢您的意见 以下是我的一些想法
希望这有帮助。如果您有更多问题,请随时提供帮助非常感谢您花时间阅读并回答。在第一点上,你不能只使用一个轴值而不是切换到morphtomy吗?我原来的系统有标记链接,但那是线性的。如果我想在其他模型上存储标记,我必须添加另一列。我正在使用一个自定义系统,在这里我使用指针,只是手工编写函数。我不明白拉威尔在幕后是如何处理事情的。
users [id, username]
links [id, user_id, url]
tags [id, user_id, text]
commentables [id, user_id, commentable, commentable_id, text] //how do i handle comment replies?
taggables [id, user_id, taggable, taggable_id, weight]
votables [id, user_id, voteable, voteable_od, vote]
favorables [id, user_id, favorable, favorable_id]
followable [id, user_id, followable, followable_id]
usersFavored() // Users which this User has Favored
usersFollowed() // Users which this User has Followed
linksSubmitted() // Links created by the User in the DB
linksFavored() // ...
tagsOnSelf() // Tags attached to this User by other Users
tagsCreated() // Tags which the User created in the DB
tags() // Tags which the User was the first to attach to a Link
tagsVoted() // Tags on which the User has Voted across the entire site
tagsFavored() // ...
tagsFollowed() // ...
commentsOnSelf() // ...
comments() // Comments across the site
commentsFavored() // ...
votesOnSelf() // ...
votes() // Votes across the site
favorites() // Favorites across the site
follows() // Follows across the site