2017-01-06 9 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) 残念ながら、私はlaravel 4.2のフォーラムのためにYouTubeのチュートリアルセリを続けました。私が今入手した唯一の参考文献は当時の私のファイルからのものなので、それを他のどのように働かせるべきかは分かりません:) – Defalt

+0

なぜコメントを付けたいのですか?その関係を「著者」と呼ぶ。関係はどのように見えますか? –

答えて

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); 
} 
関連する問題