美文网首页
Laravel学习日记2018-07-05

Laravel学习日记2018-07-05

作者: Purson | 来源:发表于2018-07-05 23:18 被阅读0次
  • 多对多关系的应用;
  • 新增或销毁多对多关联;
  • 首页动态流的具体实现;
  • 使用 with 来避免 N+1 问题;

微博产品功能

1.用户 Aufree 访问了 Summer 的个人页面进行浏览;
2.Aufree 对 Summer 发布的微博动态内容感兴趣,点击其个人页面的「关注按钮」进行关注;
3.关注之后 Aufree 将出现在 Summer 的粉丝列表,Summer 将出现在 Aufree 的关注人列表;
4.Aufree 在访问网站主页时,能够看到其他好友包括 Summer 和自己发布的动态;

多对多

1.在model里面使用$this->belongsToMany(User::class);
2.在model里面使用sync(ids,false)进行关注,使用detach(ids)取关;
3.判断A是否关注了B,在User model里面设置。

$this->followings->contains($user_id);

这里注意就是

$user->followings  == $user->followings()->get() //等于true

相关文章

网友评论

      本文标题:Laravel学习日记2018-07-05

      本文链接:https://www.haomeiwen.com/subject/nnemuftx.html