divHelper11
divHelper11

Reputation: 2208

Laravel 4 pagination links empty page

I have a query returning hundreds of database records.

As I am trying to paginate it using Laravel 4.2 method. Links are showing and they direct me to search-view?page=1 and so on, but the links open empty pages with no results. Only the first page contains results.

When I am trying to show these results without pagination the page never ends so I need to have it paginated.

Controller:

$results = $this->model->where($searchByColumn, '=', $searchKey)
                       ->paginate(30);

return View::make('search-view')
            ->with('results', $results);

View:

@foreach ($results as $result)
   {{$result}} <br>
@endforeach

{{$results->links()}}

Any help on this please?

Upvotes: 3

Views: 994

Answers (1)

dparoli
dparoli

Reputation: 9161

I guess you don't see any record on the second page probably because $searchByColumn and $searchKey are not defined, that is are defined only on the first page because entered as input of a form but not on the other pages if you follow the basic paginator links.

To persist the value of $searchByColumn and $searchKey through consecutive requests you can append them to the links generated by the paginator, something like that:

{{ $results->appends(
    array('searchByColumn' => $searchByColumn, 
    'searchKey ' => $searchKey ))->links() }}

Adjust the code to follow the names of your parameters and don't forget to pass them to the view.

Upvotes: 2

Related Questions