2014-09-01 69 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>