2017-01-06 3 views
0

내 페이지 매김에 몇 가지 문제가 있습니다. 포럼 섹션에서 내 의견을 매기려고합니다. 내 'Categories'와 'Threads'에 대해서는 정상적으로 작동했지만, 주석으로는 페이지 매김이 전혀 작동하지 않는 것 같습니다.Laravel 4.2 페이지 매김이 작동하지 않음

여기 스레드 작동하는 코드이다 :

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

왜'paginate' 함수를 사용한 후에'-> first() '를 호출하고 있습니까? – Jerodev

+0

나는,이 오류하지 않는 경우를 분명히 \ 매김 \ 매기기 : $ 아바타 (보기 : D : \ 웹 사이트 \ laravel_nfgm8 \ 응용 프로그램보기 \ \ 포럼 \의 thread.blade.php) 정의되지 않은 속성을 유감스럽게도 YouTube 튜토리얼 세리에는 Laravel 4.2의 포럼을 위해 따라 왔습니다. 처음에는 삭제되었고, 지금부터 나는 내 파일들에 대한 참고서 만 가져 왔기 때문에, 그게 더 효과적 일지는 모르겠다. :) – Defalt

+0

왜 코멘트를 매기는지 이해할 수 없다. 그 관계를'저자 (author) '라 부른다. 관계는 어떻게 생겼습니까? –

답변

0

가 좋아, 내가 그것을 수정을 발견했습니다, 나에게 맞는 유일한 방법은 스레드의 기본 메시지 (첫 번째 게시물은 데이터베이스의 forum_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()->first(); 
    $comment = $thread->comments()->paginate(5); 

    return View::make('forum.thread')->with('thread', $thread)->with('author', $author)->with('comment', $comment); 
} 
관련 문제