Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel pagination get variables

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

like image 332
notforever Avatar asked Jan 12 '23 02:01

notforever


1 Answers

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.

like image 170
Joseph Silber Avatar answered Jan 17 '23 05:01

Joseph Silber