Laravel 4.2 分页无效
Laravel 4.2 Pagination not working
我的分页有一些问题,我正在尝试对我正在创建的论坛部分的评论进行分页。它对我的 'Categories' 和 'Threads' 工作正常,但对于评论,我似乎根本无法让我的分页工作。
这是适用于线程的代码:
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);
}
好的,所以我找到了一个修复它的方法,它对我有用,唯一的问题是我现在需要找到一种方法来实现它所以线程的主要消息(第一个 post 是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);
}
我的分页有一些问题,我正在尝试对我正在创建的论坛部分的评论进行分页。它对我的 'Categories' 和 'Threads' 工作正常,但对于评论,我似乎根本无法让我的分页工作。
这是适用于线程的代码:
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);
}
好的,所以我找到了一个修复它的方法,它对我有用,唯一的问题是我现在需要找到一种方法来实现它所以线程的主要消息(第一个 post 是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);
}