Laravel 5.4-如何对紧急加载关系进行分页

Laravel 5.4-如何对紧急加载关系进行分页,laravel,pagination,relationship,eager-loading,Laravel,Pagination,Relationship,Eager Loading,我有以下代码来检索给定部分的线程及其注释和类似内容。它是有效的,但我想对结果进行分页 return $this->threads()->where('state', '=', 'active')->with('comments.likes')->get(); 一种方法是这样做,但由于不急于加载,因此会导致大量查询 return $this->threads()->where('state', '=', active)->paginate(5); 有什

我有以下代码来检索给定部分的线程及其注释和类似内容。它是有效的,但我想对结果进行分页

return $this->threads()->where('state', '=', 'active')->with('comments.likes')->get();
一种方法是这样做,但由于不急于加载,因此会导致大量查询

return $this->threads()->where('state', '=', active)->paginate(5);

有什么方法可以加载所有数据并利用Laravel的分页魔法吗?

您可以像这样分页线程:

Thread::where('section_id', $sectionId)
      ->where('state', 'active')
      ->with('comments.likes')
      ->paginate(5);

那么,如果你想加载所有的数据,那么,paginate有什么用?@RïshïKïshKümar当我说所有的数据时,我指的是关系数据。okkkk…………完美!我还发现它是这样工作的:
return$this->threads()->where('state','=','active')->with('comments.likes')->paginate(5)。我以前试过,但出现了错误,所以我一定是把事情弄糟了。非常感谢。