3

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?

12
  • provide the code for route search-view and its controller Commented Jan 25, 2018 at 11:13
  • @MahdiYounesi Route only runs the code from the first two blocks of code I provided here. There is nothing much else in there. I am getting results from database and passing them to the view, thats all. Commented Jan 25, 2018 at 11:17
  • try this paginate($30, ['*'], 'page', $request->page); Commented Jan 25, 2018 at 11:26
  • Have you tried APP_DEBUG=true? No errors in the log? Commented Jan 25, 2018 at 11:29
  • The issue is still open. Anyone :D? Commented Feb 20, 2019 at 16:36

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.