[英]Complex Comments, Tags, Votes, Favorites database relationships using Laravel
I am trying to learn HABTM and Polymorphic Relationships by building a small but complex application in Laravel 4.2. 我试图通过在Laravel 4.2中构建一个小而复杂的应用程序来学习HABTM和多态关系。 It takes in links and lets users interact with the content and each other via keywords like tag, comment, vote, favorite, and follow.
它引入了链接,并允许用户通过诸如标签,评论,投票,收藏和关注之类的关键字与内容相互交互。 I have honestly been working on this for about 3 days and feel like I am just spinning my wheels in the mud.
老实说,我已经为此工作了大约3天,感觉就像我在泥泞中转动车轮一样。 Here's the breakdown -
这是细分-
Models: 楷模:
User, Link, Tag, Comment, Vote, Favorite, Follow
Super basic use cases: 超级基本用例:
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
(assumed) Tables: (假设)表:
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]
From here .. I'm not sure that I'm doing it right. 从这里..我不确定我做对了。 I keep getting caught up in the different ways to define a relationship and I'm just wanting to understand the design completely
我不断以各种方式来定义关系,而我只是想完全了解设计
What do my model files look like? 我的模型文件是什么样的? What cases I might use belongsToMany vs morphToMany?
我可能在什么情况下使用belongsToMany和morphToMany? Is this even the right approach or should I explore using pivot tables?
这是正确的方法还是我应该探索使用数据透视表? I would appreciate some pointers on what I need to be learning to implement this correctly
我将对我需要学习以正确实现此目标的一些建议表示赞赏
Here is what my User.php will probably look like, but I'm not sure what the returns should actually be since I don't quite understand the relationship's wants/needs 这是我的User.php可能的样子,但是由于我不太了解这种关系的需求,我不确定实际的回报率是多少
(assumed) User.php (假设)User.php
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
I feel like I'm close to making this work. 我觉得我即将完成这项工作。 I have the views and routes ready because I've rebuilt this project about four times.
我已经准备好了视图和路线,因为我已经重建了该项目大约四次。 I just need to wrestle all of this database relationship logic so I can make the app come to life.
我只需要努力解决所有这些数据库关系逻辑,就可以使该应用程序栩栩如生。 Your input is much appreciated!
非常感谢您的输入!
here are some of my thoughts 这是我的一些想法
Hope this helps. 希望这可以帮助。 Ready to help if you have more questions
如果您还有其他问题,随时可以提供帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.