All Projects → spatie → Query String

spatie / Query String

Licence: mit
Manipulate query strings

Labels

Projects that are alternatives of or similar to Query String

Use Query Params
React Hook for managing state in URL query parameters with easy serialization.
Stars: ✭ 1,278 (+898.44%)
Mutual labels:  query
Ts3admin.class
The ts3admin.class is a powerful api for communication with Teamspeak 3 Servers from your website! Your creativity knows no bounds!
Stars: ✭ 103 (-19.53%)
Mutual labels:  query
Vue Screen
Reactive screen size and media query states for VueJS
Stars: ✭ 120 (-6.25%)
Mutual labels:  query
Astq
Abstract Syntax Tree (AST) Query Engine
Stars: ✭ 89 (-30.47%)
Mutual labels:  query
Elasticsearch
Use SQL statements to query elasticsearch
Stars: ✭ 98 (-23.44%)
Mutual labels:  query
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (-16.41%)
Mutual labels:  query
Hpq
Utility to parse and query HTML into an object shape
Stars: ✭ 82 (-35.94%)
Mutual labels:  query
Ldflex
A JavaScript DSL for querying Linked Data on the Web
Stars: ✭ 123 (-3.91%)
Mutual labels:  query
Geotic
Entity Component System library for javascript
Stars: ✭ 97 (-24.22%)
Mutual labels:  query
Influxdb Ui
🐎 A simple UI for InfluxDB
Stars: ✭ 117 (-8.59%)
Mutual labels:  query
Resq
React Element Selector Query (RESQ) - Query React components and children by component name or HTML selector
Stars: ✭ 89 (-30.47%)
Mutual labels:  query
Xer.cqrs
A lightweight and easy-to-use CQRS + DDD library
Stars: ✭ 96 (-25%)
Mutual labels:  query
Ts3 Nodejs Library
TeamSpeak 3 Server Query Library supports SSH and RAW Query
Stars: ✭ 110 (-14.06%)
Mutual labels:  query
Async Gamequery Lib
A high-performance java game query library designed for steam/source based games and others
Stars: ✭ 88 (-31.25%)
Mutual labels:  query
Container Query
A PostCSS plugin and Javascript runtime combination, which allows you to write container queries in your CSS the same way you would write media queries.
Stars: ✭ 119 (-7.03%)
Mutual labels:  query
Autocomplete
🔮 Fast and full-featured autocomplete library
Stars: ✭ 1,268 (+890.63%)
Mutual labels:  query
Pgtyped
pgTyped - Typesafe SQL in TypeScript
Stars: ✭ 1,734 (+1254.69%)
Mutual labels:  query
Lucenenet
Apache Lucene.NET
Stars: ✭ 1,704 (+1231.25%)
Mutual labels:  query
Mq Scss
Extremely powerful Sass media query mixin. Allows you to create almost any media query you can imagine.
Stars: ✭ 122 (-4.69%)
Mutual labels:  query
Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (-12.5%)
Mutual labels:  query

QueryString

Latest Version on Packagist run-tests Total Downloads

Work with query strings

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We 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. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/query-string

Usage

use Spatie\QueryString\QueryString;

$queryString = new QueryString($uri);

Toggle parameters

A single toggle

# / > /?toggle

$queryString->toggle('toggle');

Toggle a value

# / > /?single=a

$queryString->toggle('single', 'a');
# /?single=a > /?single=b

$queryString->toggle('single', 'b');
# /?single=a > /?

$queryString->toggle('single', 'a');

Toggle multiple values

# / > /?multi[]=a&multi[]=b

$queryString->toggle('multi[]', 'a');
$queryString->toggle('multi[]', 'b');
# /?multi[]=a&multi[]=b > /?multi[]=a

$queryString->toggle('multi[]', 'b');

Filter

Filtering the query string will use the JSON API filter syntax.

# / > /?filter[field]=a

$queryString->filter('field', 'a');
# / > /?filter[field][]=b

$queryString->filter('field[]', 'b');

Sort

Sorting the query string will use the JSON API sort syntax. At the moment only single sorts are supported.

# / > /?sort=field > /?sort=-field > /?sort=field

$queryString->sort('field');
$queryString->sort('field');
$queryString->sort('field');

Pagination

There's built-in support for pagination:

$queryString->page(10); # /?page=10
$queryString->nextPage(); # /?page=11
$queryString->previousPage(); # /?page=9
$queryString->resetPage(); # /?

$queryString->isCurrentPage(1); # true

Note that changing any other value on the query string, will reset the page too.

Other useful methods

Base URL

Casting a QueryString to a string will generate the URL. You can choose to use a different base URL like so:

$queryString->withBaseUrl('https://other.url');

Clear a parameter

# /?toggle > /

$queryString->clear('toggle');
# /?single=b > /

$queryString->clear('single');
# /?multi[]=a&multi[]=b > /

$queryString->clear('multi[]');

Active parameter or not

# /?multi[]=a

$queryString->isActive('multi[]'); # true
$queryString->isActive('multi[]', 'a'); # true
$queryString->isActive('multi[]', 'b'); # false
# /?single=a

$queryString->isActive('single'); # true
$queryString->isActive('single', 'a'); # true
$queryString->isActive('single', 'b'); # false
# /?toggle

$queryString->isActive('toggle'); # true

Laravel support

A separate Laravel package will be added in the future. The Laravel package will use this one under the hood and implement the JSON API spec.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You'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.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].