sauladam's avatar

Pagination and urlencoded arrays

I want to filter my results, say, by a status. I want all posts that have one of the given statuses. I pass the statuses array through the query string (actually coming from a form with a multi-select):

posts?statuses[0]=new

I pass the statuses array to the pagination renderer with

$posts->prepends($statuses)->render();

And Laravel of course urlencodes the the URLs:

posts?statuses%5B0%5D=new&page=2

The problem now is: If i click on that pagination url, the "%" sign gets also urlencoded in the next request, so I'm redirected to:

posts?statuses%255B0%255D=new&page=2

which of course is not correct. Is this a Laravel specific issue (maybe some urlencoding somewhere in the middleware?) or does the browser mess this up? I've tried both Chrome and Firefox and both give the same results.

Does anybody else have this problem? What could be a way to work around it?

0 likes
8 replies
unamix's avatar

Hi sauladam,

I have the same problem.. Did you find a solution?

sauladam's avatar

@unamix Nope, not yet... :-/ But haven't really worked on it since then. As soon as I find out how to fix it I'll post it here.

unamix's avatar

How about this?

urldecode($posts->prepends($statuses)->render())

NedStrk's avatar

Did some one find good solution for this? $listings->appends(Request::query())->render() if query contains array than pagination messes it up... type[]=5 after page change it becomes type%255B0%255D=5

1 like
QuentinBontemps's avatar

Well, i did it like this :

foreach($request->all() as $key => $param)
{
    $request->merge([$key => rawurldecode($param)]);
}

I know that isn't the optimal solution, but it works.

1 like
kendysond's avatar

So I made a mini fix on my end for adding arrays to your url

///Subcategories being the array of values on the URL  
$ssc = '';
      foreach ($subcategories as $key => $value) {
        $ssc.= '&subcategory[]='.$value;
      }
    //Profiles being the eloquent to paginate
      $profiles = $profiles->paginate(1);///get();
///search being the root path of your page
      $profiles->setPath('search?'.$ssc);

anon4664's avatar

I've the same problem. Some issue tracked?

Please or to participate in this conversation.