Support the ongoing development of Laravel.io →
Authentication Eloquent Views
Last updated 1 year ago.
0

OK I just solved it. Put this into the view and it works like a champ:

{{ $trucks->appends(Input::query())->links() }}

lwilliamsjr said:

I'll start by saying i've already consulted the Laravel 4 documentation on Pagination and tried many methods to get this to work. Do I need to Append query string to pagination?

I am using Eloquent together with Laravel 4's Pagination class.

Problem: In my results page, i'm trying to paginate my results for what we'll call "trucks" DB. It works fine and I get exactly what I want at first (a limit of five results). Problem is when I click one of the page numbers (which don't appear to be accurate) created by pagination, the whole DB is queried and it takes me to the wrong page. I'm using where clauses and three dropdowns to limit the searcher's results but the pagination screws all that up. Here's a look at my controller logic:

$results = $query->Paginate(5);
   return View::make('results')->with('trucks', $results);

Blade Template

@if ($trucks) 
   @foreach ($trucks as $truck)
{{ $trucks->link() }}

How can I make sure that the page numbers work correctly and don't query the entire DB? Thanks in advance.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.