config/ziggy.php file in your Laravel application. All configuration options are optional.
Creating the Config File
Create a configuration file atconfig/ziggy.php:
Configuration Options
only
Include only routes matching the specified patterns.array
Array of route name patterns to include. Supports wildcards (Only these routes will be available to Ziggy’s JavaScript.
*).except
Exclude routes matching the specified patterns.array
Array of route name patterns to exclude. Supports wildcards (These routes will be hidden from Ziggy’s JavaScript output.
*).groups
Define named groups of routes that can be loaded selectively.array
Array of group names, each containing an array of route patterns.
middleware
Include route middleware in Ziggy’s output.boolean|array
Control middleware inclusion:
false(default): Don’t include middlewaretrue: Include all middlewarearray: Include only specified middleware
output
Customize output paths and classes for generated files.array
Configure output behavior for different Ziggy features.
output.path
string
default:"resources/js/ziggy.js"
Default output path for
php artisan ziggy:generate.output.types-path
string
default:"resources/js/ziggy.d.ts"
Default output path for TypeScript definitions.
output.file
string
default:"\\Tighten\\Ziggy\\Output\\File"
Custom class for generating JavaScript files.
output.types
string
default:"\\Tighten\\Ziggy\\Output\\Types"
Custom class for generating TypeScript declarations.
output.script
string
default:"\\Tighten\\Ziggy\\Output\\Script"
Custom class for
@routes Blade directive output.output.json
string
default:"\\Tighten\\Ziggy\\Output\\Json"
Custom class for JSON output (when using
@routes(json: true)).output.merge_script
string
default:"\\Tighten\\Ziggy\\Output\\MergeScript"
Custom class for subsequent
@routes calls on the same page.skip-route-function
Disable the route helper function in@routes output.
boolean
default:false
When Useful when importing the route function separately from the NPM package.
true, the @routes directive only outputs route configuration (no route() function).@routes outputs:
route() separately:
Complete Example
Here’s a comprehensive configuration example:Common Configurations
Secure Configuration (Hide Admin Routes)
API-Only Configuration
Multi-Tenant Configuration
SPA Configuration
Security Considerations
Best practices:- Use route filtering to keep your JavaScript bundle smaller and reduce information exposure
- Always implement authentication/authorization on your routes
- Don’t rely on obscurity - assume all route names are public
- Use groups to load only necessary routes on each page
Related
Blade Directive
Use @routes with configured groups and filters
Artisan Commands
Generate files with configured paths
Ziggy Class
Understand how configuration affects the Ziggy class