Strengths:
Request::query() returns arrays, but this library standardizes parsing/serialization). Ideal for APIs, webhooks, or integrations where query strings are dynamic (e.g., pagination, filtering).parse_str/http_build_query (e.g., repeated keys, nested arrays, malformed URLs). Example: Converts foo=bar&foo=baz → foo[]=bar&foo[]=baz, critical for APIs like Google Fonts.array and string representations, reducing bugs in URL generation (e.g., Route::parameters() or URL::to()).Gaps:
Validator or Request validation.Route middleware.Request::query() with:
use Crwlr\QueryString\Query;
$query = new Query(Request::query());
$nested = $query->get('filter[foo][]'); // Returns array values.
toString() for URL::to() or route() calls:
$params = ['page' => 2, 'sort[]' => ['name', 'asc']];
$query = new Query($params);
$url = route('search', ['query' => $query->toString()]);
POST query strings (e.g., from application/x-www-form-urlencoded):
$query = new Query($request->getContent());
[] arrays, malformed strings).&foo=bar, foo=bar&, nested arrays).Request::query() and URL::to() to validate edge cases (e.g., filter%5Bfoo%5D%5B%5D=1).parse_str/http_build_query as a backup for non-critical paths.Request::query() and Query output during ramp-up.tags[]=php&tags[]=laravel) or nested arrays in query strings? If not, Laravel’s built-ins may suffice.foo=bar&foo=baz → array) are critical here.Query vs. parse_str/http_build_query. The library adds minimal overhead (~1–2ms for complex strings).HttpFoundation: Offers QueryString utilities but is heavier. Prefer this if you’re already using Symfony components.[] arrays), parse_str/http_build_query may suffice.parse_str($_GET, $query) with:
$query = new Query(Request::query());
toString() for dynamic routes:
Route::get('/search', function (Query $query) {
return $query->get('q'); // Access nested params easily.
});
POST data with application/x-www-form-urlencoded:
$query = new Query($request->getContent());
$params = ['page' => 2, 'sort' => ['name', 'asc']];
$query = new Query($params);
return redirect()->to("https://example.com?{$query->toString()}");
parse_url:
$url = 'https://example.com?foo=bar&foo=baz';
parse_str(parse_url($url, PHP_URL_QUERY), $query);
$normalized = new Query($query); // Converts to foo[]=bar&foo[]=baz
foo=bar&foo=baz → foo[]=bar&foo[]=baz.filter[foo][bar][]=1.&foo=bar, foo=bar&.parse_str).Query usage.get(), set(), toString()).parse_str/http_build_query calls with Query.Request::query(), Request::getContent().Route::parameters() and URL::to().Validator for schema enforcement.toString() to generate URLs for Guzzle, HTTP clients.mbstring, filter, or xml extensions.parse_str calls first (low risk, high reward).parse_str($_GET, $query) to new Query($_GET).toString() for URL generation (e.g., redirects, API calls).&foo=bar → foo=bar).Query usage (e.g., "Always use Query for query strings with [] arrays").How can I help you explore Laravel packages today?