I don't use \Request::query(), but I have successfully passed an array something like this:
$array = [
'foo' => 1,
'bar' => 2,
];
$listings->appends($array)->render();
the problem is that my query string is dynamic... the code from the 1st post worked great in laravel 4
type%255B0%255D=5
is type[0]=5
url-encoded twice.
I don't know why the second encoding happens, but your code:
$listings->appends(Request::query())->render();
works fine with arrays in query in my test (Laravel 5), so it must be something else.
Try to pass a constant array to appends():
$listings->appends([ 'type' => [5,7,8] ])->render();
to see if it gets mangled by pagination.
thanks for the reply! it still does url-encoding, but now it does it only once (type%255B0%255D=5&page=2)
A single encoding looks like this: type%5B0%5D=5
.
type%255B0%255D=5&page=2
is double encoding, but you say it only encodes once. So which is it?
Oh, and could you var_dump(Request::query())
and post it here, too.
array(2) { ["type%5B0%5D"]=> string(1) "5" ["page"]=> string(1) "2" } array(2) { ["type%255B0%255D"]=> string(1) "5" ["page"]=> string(1) "3" }
thanks
And here's an example of how it should have looked like:
array(2) {
["region"]=>
array(4) {
[0]=>
string(1) "2"
[1]=>
string(1) "3"
[2]=>
string(1) "6"
[3]=>
string(1) "7"
}
["page"]=>
string(1) "2"
}
So, paginator is actually working correctly, the error is somewhere else, probably at the point where you set those query parameters. Maybe it's in the form, check that the field name is type[]
(and not something like type%5B%5D
).
this is what I get from the form
array(3) { ["type"]=> array(1) { [0]=> string(1) "5" } ["bedrooms"]=> string(0) "" ["bathrooms"]=> string(0) "" }
and this is what it becomes after page change
array(4) { ["type%5B0%5D"]=> string(1) "5" ["bedrooms"]=> string(0) "" ["bathrooms"]=> string(0) "" ["page"]=> string(1) "2" }
as we can see pagination changes type[array] to type[string]
Could this be an issue of this transformation? https://github.com/illuminate/pagination/commit/25c7ee4c3b3c4b5161c53aa71daad9408e2ea664
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community