{"id":19325069,"url":"https://github.com/spatie/query-string","last_synced_at":"2025-04-04T20:15:17.096Z","repository":{"id":46016081,"uuid":"161786309","full_name":"spatie/query-string","owner":"spatie","description":"Manipulate query strings","archived":false,"fork":false,"pushed_at":"2022-12-11T17:12:11.000Z","size":67,"stargazers_count":159,"open_issues_count":1,"forks_count":10,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-05-09T22:22:04.898Z","etag":null,"topics":["http","manipulate","php","query"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2018-12-14T13:12:01.000Z","updated_at":"2024-04-04T21:05:24.000Z","dependencies_parsed_at":"2023-01-27T03:35:21.257Z","dependency_job_id":null,"html_url":"https://github.com/spatie/query-string","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fquery-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fquery-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fquery-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fquery-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/query-string/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242681,"owners_count":20907134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","manipulate","php","query"],"created_at":"2024-11-10T02:08:47.783Z","updated_at":"2025-04-04T20:15:17.076Z","avatar_url":"https://github.com/spatie.png","language":"PHP","readme":"\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/support-ukraine.svg?t=1\" /\u003e](https://supportukrainenow.org)\n\n# QueryString\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/query-string.svg?style=flat-square)](https://packagist.org/packages/spatie/query-string)\n![run-tests](https://github.com/spatie/query-string/workflows/run-tests/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/query-string.svg?style=flat-square)](https://packagist.org/packages/spatie/query-string)\n\nWork with query strings\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/query-string.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/query-string)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/query-string\n```\n\n## Usage\n\n``` php\nuse Spatie\\QueryString\\QueryString;\n\n$queryString = new QueryString($uri);\n```\n\n### Toggle parameters\n\n#### A single toggle\n\n```php\n# / \u003e /?toggle\n\n$queryString-\u003etoggle('toggle');\n```\n\n#### Toggle a value\n\n```php\n# / \u003e /?single=a\n\n$queryString-\u003etoggle('single', 'a');\n```\n\n```php\n# /?single=a \u003e /?single=b\n\n$queryString-\u003etoggle('single', 'b');\n```\n\n```php\n# /?single=a \u003e /?\n\n$queryString-\u003etoggle('single', 'a');\n```\n\n#### Toggle multiple values\n\n```php\n# / \u003e /?multi[]=a\u0026multi[]=b\n\n$queryString-\u003etoggle('multi[]', 'a');\n$queryString-\u003etoggle('multi[]', 'b');\n```\n\n```php\n# /?multi[]=a\u0026multi[]=b \u003e /?multi[]=a\n\n$queryString-\u003etoggle('multi[]', 'b');\n```\n\n### Filter\n\nFiltering the query string will use the JSON API filter syntax.\n\n```php\n# / \u003e /?filter[field]=a\n\n$queryString-\u003efilter('field', 'a');\n```\n\n```php\n# / \u003e /?filter[field][]=b\n\n$queryString-\u003efilter('field[]', 'b');\n```\n\n### Sort\n\nSorting the query string will use the JSON API sort syntax.\nAt the moment only single sorts are supported.\n\n```php\n# / \u003e /?sort=field \u003e /?sort=-field \u003e /?sort=field\n\n$queryString-\u003esort('field');\n$queryString-\u003esort('field');\n$queryString-\u003esort('field');\n```\n\n### Pagination\n\nThere's built-in support for pagination:\n\n```php\n$queryString-\u003epage(10); # /?page=10\n$queryString-\u003enextPage(); # /?page=11\n$queryString-\u003epreviousPage(); # /?page=9\n$queryString-\u003eresetPage(); # /?\n\n$queryString-\u003eisCurrentPage(1); # true\n```\n\nNote that changing any other value on the query string, will reset the page too.\n\n### Other useful methods\n\n#### Base URL\n\nCasting a `QueryString` to a string will generate the URL. \nYou can choose to use a different base URL like so:\n\n```php\n$queryString-\u003ewithBaseUrl('https://other.url');\n```\n\n#### Clear a parameter\n\n```php\n# /?toggle \u003e /\n\n$queryString-\u003eclear('toggle');\n```\n\n```php\n# /?single=b \u003e /\n\n$queryString-\u003eclear('single');\n```\n\n```php\n# /?multi[]=a\u0026multi[]=b \u003e /\n\n$queryString-\u003eclear('multi[]');\n```\n\n#### Active parameter or not\n\n```php\n# /?multi[]=a\n\n$queryString-\u003eisActive('multi[]'); # true\n$queryString-\u003eisActive('multi[]', 'a'); # true\n$queryString-\u003eisActive('multi[]', 'b'); # false\n```\n\n```php\n# /?single=a\n\n$queryString-\u003eisActive('single'); # true\n$queryString-\u003eisActive('single', 'a'); # true\n$queryString-\u003eisActive('single', 'b'); # false\n```\n\n```php\n# /?toggle\n\n$queryString-\u003eisActive('toggle'); # true\n```\n\n### Laravel support\n\nA separate Laravel package will be added in the future.\nThe Laravel package will use this one under the hood and implement the JSON API spec.\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n### Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Postcardware\n\nYou're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.\n\nOur address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.\n\nWe publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).\n\n## Credits\n\n- [Brent Roose](https://github.com/brendt)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":["https://spatie.be/open-source/support-us"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fquery-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fquery-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fquery-string/lists"}