Laravel 4.2 Pagination not working

289 views Asked by At

I'm having some issues with my pagination, I'm trying to paginate my comments on a forum section I'm making. It worked fine for my 'Categories' and 'Threads', but for comments, I can not seem to get my paginations to work at all.

Here's the code that works for 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);
}

And here's the code that doesn't work for comments:

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);
}
1

There are 1 answers

0
Defalt On BEST ANSWER

Okay, so I've found a fix for it, which works for me, only thing is I now need to find a way to make it so the thread's primary message (first post is part of forum_threads on database) works together with the pagination of comments, however, the comments themselves get paginated now. The code I used to do so:

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);
}