Overview
Ziggy automatically adds arguments that don’t match any named route parameters as query parameters. This makes it easy to add filters, pagination, and other query strings to your URLs.Automatic Query Parameters
Any parameters that don’t match route segments are automatically appended as query parameters:venueandeventare route parameters (matched to{venue}and{event})pageandcountdon’t match any route segments, so they become query parameters
The _query Key
Sometimes you need to pass a query parameter with the same name as a route parameter. Use the special _query key to handle these conflicts:
Parameters inside
_query are always treated as query parameters, even if they match route parameter names.When to Use _query
Boolean Query Parameters
Ziggy automatically encodes boolean values as integers, matching Laravel’s behavior:This behavior is implemented in the
encoder function (Router.js:65-66) using Ziggy’s query string serializer:Working with Arrays
Ziggy uses theindices array format for query parameters:
Query String Format Details
Query String Format Details
Ziggy uses the qs library with these options:
addQueryPrefix: true- Adds the?prefixarrayFormat: 'indices'- Arrays becomekey[0]=value&key[1]=valueencodeValuesOnly: true- Only encodes values, not keysskipNulls: true- Omits null/undefined values
Null and Undefined Values
Null and undefined parameters are automatically skipped:Nested Objects
You can pass nested objects as query parameters:Common Use Cases
Pagination
Filtering and Sorting
Search with Route Parameters
Tab or View State
Implementation Details
How Query Parameters Are Extracted
How Query Parameters Are Extracted
The This:
toString() method in Router.js handles query parameter extraction:- Identifies parameters that don’t match route segments
- Excludes the
_querykey itself - Merges unmatched parameters with
_querycontents - Serializes them using the
qslibrary
Best Practices
Use _query sparingly
Use _query sparingly
Only use
_query when you have naming conflicts. For most cases, automatic query parameter handling is cleaner:Keep query parameters flat when possible
Keep query parameters flat when possible
Match Laravel's parameter expectations
Match Laravel's parameter expectations
Make sure your query parameters match what your Laravel controller expects:
Next Steps
Route-Model Binding
Learn about route-model binding in Ziggy
Default Parameters
Set default parameter values for your routes