我的分页存在一些问题,我正试图在我正在制作的论坛部分中对我的评论进行分页。它适用于我的“类别”和“主题”,但是对于评论,我似乎无法让我的分页工作。
以下是适用于线程的代码:
public function category($id){
$category = ForumCategory::find($id);
if ($category == null){
return Redirect::route('forum')->with('fail', "That category doesn't exist.");
}
$threads = $category->threads()->paginate(10);
return View::make('forum.category')->with('category', $category)->with('threads', $threads);
}
这里的代码不适用于评论:
public function thread($id){
$thread = ForumThread::find($id);
if ($thread == null){
return Redirect::route('forum')->with('fail', "That thread doesn't exist.");
}
$author = $thread->author()->paginate(5)->first();
return View::make('forum.thread')->with('thread', $thread)->with('author', $author);
}
答案 0 :(得分:0)
好的,所以我找到了一个修复它,对我有用,唯一的事情是我现在需要找到一种方法来使它成为线程的主要信息(第一篇文章是其中的一部分) forum_threads on database)与评论的分页一起工作,然而,评论本身现在被分页。我曾用过的代码:
public function thread($id){
$thread = ForumThread::find($id);
if ($thread == null){
return Redirect::route('forum')->with('fail', "That thread doesn't exist.");
}
$author = $thread->author()->first();
$comment = $thread->comments()->paginate(5);
return View::make('forum.thread')->with('thread', $thread)->with('author', $author)->with('comment', $comment);
}