讨论数量:
上一节讲过N+1的问题,模仿上一节话题的解决方案可以解决。
CategoriesController.php
$topics = Topic::where('category_id', $category->id)->with('user','category')->paginate(20);
@rundong 我先调用with比后调用 运行时间要少一半,具体原因还没研究
$topics = Topic::with('user', 'category')->where('category_id', $category->id)->paginate(20);
推荐文章: