Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel:是否可以使用递归注释/回复?_Laravel_Recursion_Eloquent_Polymorphic Associations - Fatal编程技术网

Laravel:是否可以使用递归注释/回复?

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([

我正在寻找一种最具资源效率和可扩展性的方法来检索数据,以便在社交媒体应用程序中构建一系列多模型(Post、User、Like、Comment)Post对象,其中包括递归评论(comments to comments)。我最近开始尝试使用许多关系,但看不出它们如何与递归注释一起工作

在我的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
  • 可注释的
  • 可注释类型
  • 身体
  • 时间戳
  • 我正在使用一个特征来抽象注释之间的许多关系,这样
    comments.comments
    是可能的。但我不知道或者在任何地方都找不到如何递归地做到这一点

    Laravel的许多关系,连同traits,是否与递归注释兼容