Laravel:是否可以使用递归注释/回复?
我正在寻找一种最具资源效率和可扩展性的方法来检索数据,以便在社交媒体应用程序中构建一系列多模型(Post、User、Like、Comment)Post对象,其中包括递归评论(comments to comments)。我最近开始尝试使用许多关系,但看不出它们如何与递归注释一起工作 在我的PostController中,我使用以下查询返回一个Laravel:是否可以使用递归注释/回复?,laravel,recursion,eloquent,polymorphic-associations,Laravel,Recursion,Eloquent,Polymorphic Associations,我正在寻找一种最具资源效率和可扩展性的方法来检索数据,以便在社交媒体应用程序中构建一系列多模型(Post、User、Like、Comment)Post对象,其中包括递归评论(comments to comments)。我最近开始尝试使用许多关系,但看不出它们如何与递归注释一起工作 在我的PostController中,我使用以下查询返回一个$posts数组: $posts = Post::whereIn('user_id', $friendIds)->with([
$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();
注释表具有以下结构:
comments.comments
是可能的。但我不知道或者在任何地方都找不到如何递归地做到这一点
Laravel的许多关系,连同traits,是否与递归注释兼容