laravel - Laravel:morphMany 可以递归评论/回复?
问题描述
我正在寻找最节省资源和可扩展的方式来检索构建多模型数组所需的数据——发布、用户、喜欢、评论——在包含递归评论(评论)的社交媒体应用程序中发布对象到评论)。我最近开始尝试 morphMany 关系,但看不到它们如何与递归评论一起工作。
在我的 PostController 中,我$posts
使用此查询返回一个数组:
$posts = Post::whereIn('user_id', $friendIds)->with([
'comments.user:id,name',
'comments.likes.user:id',
'comments.comments.user:id,name',
'comments.comments.likes.user:id',
'user',
'likes.user:id'])
->get();
注释表具有以下结构:
- ID
- 用户身份
- commentable_id
- 可评论类型
- 身体
- 时间戳
我正在使用一个特征来抽象评论之间的 morphMany 关系,这comments.comments
是可能的。但我无法弄清楚或找到任何地方如何递归地做到这一点。
Laravel 的 morphMany 关系以及特征是否与递归注释兼容?
解决方案
推荐阅读
- sql-server - SQL Server SSIS 支持访问
- java - 使用 Mockito 模拟 JasonNode
- flutter - 我在颤振上使用 webview。页面有收藏链接功能。我如何在个人资料页面中调用和列出收藏的链接?
- firebase - 我的 GAE 本地服务器如何连接到 firebase 模拟器
- function - FaaS 容器化函数内存预置 - AWS Lambda
- html - 使用XPath获取Div值知兄弟Span值
- asp.net - Angular:ng-reflect 属性未显示在已发布的应用程序中
- python - 需要python字符串格式化解释
- reactjs - 组件数组状态添加的元素被删除
- perforce - Perforce 集成来自另一台服务器的文件