1
votes

hi :) im parsing my database in a table with pagination !!

this is my controller

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

and my view i have {{ $questions->links(); }} under my table and it's working fine !! the thing is that i have a list of themes to sort data in the table so when i click on divertisement i get divertisement data. the problem is that when i paginate it return to the get request and give me all the data !! what is the problem thx :)

1

1 Answers

1
votes

To add a filter/sort you also need to add that in a where clause in your query and also you need to append the query string in your pagination links. For example:

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

In your view you need to create links to this method (Probably using a route name or url) with filter query string. So, for example:

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