Home > Blockchain >  Remove specific parameters from URL while leaving others intact
Remove specific parameters from URL while leaving others intact

Time:01-28

I have a few filters on my view which a user can select. Let's say in this example it is a webshop and the user is viewing a page to buy t-shirts. On the sidebar the user can select a few parameters which will be added to the URL:

https://www.myshop.com/shirts?size=22&gender=male&somethingelse=true

Now when the user clicks on view all sizes, I want the size=22 to be removed from the URL while keeping the other parameters intact:

https://www.myshop.com/shirts?gender=male&somethingelse=true

I found somewhere to do that, I have to do the following in my blade file (Mind you I need to do this from the blade view, not from any controller or helper method):

<a href="{{ route('shop.shirts', http_build_query(request()->except('size'))) }}">View all sizes</a>

But this does not work, it keeps the size=22 in the URL. What am I missing here, or is there perhaps a different approach to this?

Edit: Added dump of request()

enter image description here

In my example I am using a webshop but in my actual site I am using date and category, but the base functionality is the same.

CodePudding user response:

Have you tried : request()->query->except('size') ?

Regards,

CodePudding user response:

In the end, this did work after all:

<a href="{{ route('shop.shirts', http_build_query(request()->except('size'))) }}">View all sizes</a>

I think I did something wrong in the beginning. After revisiting this solution, it worked.

  • Related