5

I am using the following code to append the query strings with two links. But I want to exclude the page parameter of pagination from the query string.

<li><a href="/teachers?{{ Request::getQueryString()}}">Teachers</a></li>

<li><a href="/courses?{{ Request::getQueryString()}}">Courses</a></li>

What is the way to do it? I tried the following code but it generates error.

<li><a href="/teachers?{{ Request::getQueryString()->except('page') }}">Teachers</a></li>

<li><a href="/courses?{{ Request::getQueryString()->except('page') }}">Courses</a></li>
Hassan Saqib
  • 2,597
  • 7
  • 28
  • 51

1 Answers1

10

Well getQueryString() just returns a string. Instead you can use Request::except() directly and then call http_build_query() to generate the query string:

<li><a href="/teachers?{{ http_build_query(Request::except('page')) }}">Teachers</a></li>

Note that if you have POST values, those will be included too. If you want to avoid that do this:

<li><a href="/teachers?{{ http_build_query(array_except(Request::query(), 'page')) }}">Teachers</a></li>
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270