Skip to main content
Ziggy can be configured using a config/ziggy.php file in your Laravel application. All configuration options are optional.

Creating the Config File

Create a configuration file at config/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.
You cannot use both only and except at the same time. If both are set, Ziggy will ignore both and include all routes.
Example:

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.
Example:

groups

Define named groups of routes that can be loaded selectively.
array
Array of group names, each containing an array of route patterns.
Example:
Usage:

middleware

Include route middleware in Ziggy’s output.
boolean|array
Control middleware inclusion:
  • false (default): Don’t include middleware
  • true: Include all middleware
  • array: Include only specified middleware
Example:
Output:

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.
Complete output configuration:

skip-route-function

Disable the route helper function in @routes output.
boolean
default:false
When true, the @routes directive only outputs route configuration (no route() function).
Useful when importing the route function separately from the NPM package.
Example:
With this setting, @routes outputs:
You’ll need to import 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

Hiding routes from Ziggy’s output is not a security measure. Always protect your routes with proper authentication and authorization, regardless of whether they appear in Ziggy’s configuration.
Best practices:
  1. Use route filtering to keep your JavaScript bundle smaller and reduce information exposure
  2. Always implement authentication/authorization on your routes
  3. Don’t rely on obscurity - assume all route names are public
  4. Use groups to load only necessary routes on each page

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