问题描述
我正在寻找一种资源效率最高且可扩展的方法来检索构建多模型数组所需的数据 – 发布、用户、赞、评论 – 在包含递归的社交媒体应用程序中发布对象评论(评论评论)。我最近开始试验 morphMany 关系,但看不出它们如何与递归评论一起工作。
在我的 PostController 中,我使用这个查询返回一个 $posts
数组:
$posts = Post::whereIn('user_id',$friendIds)->with([
'comments.user:id,name','comments.likes.user:id','comments.comments.user:id,'comments.comments.likes.user:id','user','likes.user:id'])
->get();
comments 表的结构如下:
- id
- user_id
- commentable_id
- commentable_type
- 身体
- 时间戳
我正在使用 trait 来抽象注释之间的 morphMany 关系,这样 comments.comments
是可能的。但我无法弄清楚或找不到如何递归地做到这一点。
Laravel 的 morphMany 关系,结合 trait,是否兼容递归注释?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)