Lynx
Lynx

Reputation: 1482

Laravel 4 paginate on GET request

I have a form that is used to filter results for a categories page. So, the URL will be localhost/public/search?keyword=blue however when I attempt to paginate() them the URL shows up as localhost/public/search?page=2 and so on. If I manually add the page=2 part to the end of the url it works fine but it's not adding it to the URL with the get request as needed. It needs to show up as localhost/search?keyword=blue&page=2

Not sure if needed but here is my method that handles the paginate()

        $category = Inventory::select('inventory_images.image', 'inventory.id' , 'inventory.sku', 'inventory.name', 'inventory.price', 'inventory_categories.category')
            ->join('inventory_categories', 'inventory.sku', '=', 'inventory_categories.sku')
            ->leftJoin('inventory_images', 'inventory.sku', '=', 'inventory_images.sku')
            ->where('inventory.active', '=', 1)
            ->where('inventory.stock_quantity', '>', 2)
            ->where('inventory.description', 'LIKE', '%'. Input::get('keyword') . '%')
            ->orWhere('inventory.name', 'LIKE', '%'. Input::get('keyword') . '%')
            ->groupby('inventory.id')
            ->take(1000)
            ->paginate(16);

Upvotes: 0

Views: 201

Answers (1)

Andreyco
Andreyco

Reputation: 22862

The problem is in your view file, where pagination is printed.
You need to append query parameters to links generated by Eloquent's paginator - which is pretty simple!

<div class="pagination">
    {{ $model->appends(Input::except('page'))->links() }}
</div>

Note: you must append everything except the page query parameter. If you don't, it would be included twice in the URL.

Upvotes: 2

Related Questions