2014-09-01 49 views
1

嗨:)即時解析我的數據庫在一個表與分頁!laravel post on post

這是我的控制器

$theme = Theme::all(); 
      $questions = questionList::paginate(10); 
      $the = ""; 
      return View::make('home.home') 
      ->with('user',Auth::user()) 
      ->with('theme', $theme) 
      ->with('the' , $the) 
      ->with('questions',$questions); 

和我的觀點,我有我的{{ $questions->links(); }}桌子底下它的正常工作! 的事情是,我有一個主題列表來排序表中的數據,所以當我點擊divertisement我得到divertisement數據。 問題是,當我分頁它回到獲取請求,並給我所有的數據!這是什麼問題:) THX

回答

1

添加filter/sort還需要補充的是在where子句中您query,你也需要附加在分頁鏈接的query string。例如:

public function showPosts() 
{ 
    $questions = app('questionList'); 

    if($filter = Input::get('filter')) { 
     $questions = $questions->where('theme', $filter); 
    } 

    $questions = $questions->paginate(10); 

    if(isset($filter)) { 
     $questions->appends('filter', $filter); 
    } 

    return View::make(...)->with(...); 
} 

在你view,你需要創建鏈接到這種方法(可能使用路由名稱或網址)與filter查詢字符串。因此,例如:

<a href="{{ 'link to that method' }}?filter=divertisement">Divertisement</a> 
<a href="{{ 'link to that method' }}?filter=SomethingElse">SomethingElse</a>