4

I have a page that list apartments depending on book dates like this

mypage.com/finder?date-from=2011-03-04&date-to=2011-03-12

Everything is right, I am getting the date-from and date-get from the url and searching the database with those values. The problem is when I paginate and I click to go to another page the url changes to.

mypage.com/finder?page=9 

and get an error Value must be provided

The correct url must be

mypage.com/finder?date-from=2011-03-04&date-to=2011-03-12&page=9

I am using paginate at the controller and $searchResult->links(); to generate the links

What can I do pass the date values from page to page so the pagination works?

Thanks

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
notforever
  • 569
  • 4
  • 12
  • 23

2 Answers2

8

If you want to tack on existing query string data, use this:

$searchResult->appends(array(
    'date-from' => Input::get('date-from'),
    'date-to'   => Input::get('date-to'),
));

Read the docs: Appending To Pagination Links.


You can shorten that a little:

$searchResult->appends( Input::only('data-from', 'date-to') );

which ends up being the same thing.

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • I think a better approach would be - Laravel first check for existing query string and if present, append to it else start from ?page=n. The issue with the current approach is when you click on the paging link again then your previous sorting variables are discarded. – elf1984 Jul 20 '14 at 23:04
1

you can do this using the 'appends' feature. There are examples in the documentation: http://laravel.com/docs/pagination

Darren Craig
  • 462
  • 3
  • 8