在嵌套评论里使用Like出现多条数据重复加载的问题?
f4xy opened this issue · 3 comments
f4xy commented
解决不了问题,还是自己开发吧。谢谢啦
overtrue commented
建议你把代码贴全,另外代码的格式是:
```php
代码贴这里
```
overtrue commented
从代码看应该是子评论部分导致
//在子评论中attachLikeStatus,以便使用has_liked状态
auth()->user()->attachLikeStatus($comment->children;)
overtrue commented
- 评论改成平级
- 两个包不会出现 N+1
还有一个暴力的方案:
$comments = $this->model->comments()
->with('likers', 'user', 'children.user','children.children.likers', 'children.likers')
->withCount(['children','likers'])
->parent()
->latest()
->paginate(15);
不过还是建议你的评论不要这样设计三层结构,无线层级也应该是扁平拉取然后再组装