jdebuchy's avatar

Pagination links() with request that are only built with key

I have a set of records that needs to be paginated. Based on a Laracast's lesson I added a popular filter that will sort by "most viewed" restaurants. This query doesn't have any value like popular=true, only a key.

If my request is ?cuisine=pasta&popular&page=2 and I try to create pagination using

{{ $restaurants->appends(request()->input())->links() }}

the url for page 3 will remove popular key and only show ?cuisine=pasta&page=3.

How can I keep this popular query across navigation?

Thanks!

0 likes
3 replies
jdebuchy's avatar

Thanks for your answer @michaloravec. Unfortunately this is not working. I guess it has to do with the fact that popular value is null.

#query: array:2 [
    "cuisine" => "pasta"
    "popular" => null
 ]
jlrdw's avatar

Both sides of = needs something like

popular=true

see https://stackoverflow.com/questions/6461668/boolean-in-a-uri-query

Compare:

tjhs/dog/indexadmin?p=2&psch=&aval=n

tjhs/dog/indexadmin?p=2&psch=c&aval=y

aval is a boolean for is the dog available for adoption or not.

First line search name field is blank to show all, therefore

psch=

Query string works the same in all languages, php, java, asp.net, etc.

Please or to participate in this conversation.