Skip to main content

Installation

Ziggy can be installed in any Laravel application using Composer. For SPAs or applications with separate frontend repositories, you can also install the NPM package.

Requirements

  • PHP: 8.1 or higher
  • Laravel: 9.0 or higher
  • JSON extension: Required for PHP

Composer Installation

Install Ziggy via Composer in your Laravel application:
Ziggy uses Laravel’s package auto-discovery, so the service provider will be automatically registered.
No additional configuration is required. Ziggy is ready to use immediately after installation.

NPM Installation (Optional)

For applications using JavaScript bundlers like Vite or Webpack, you can optionally install Ziggy’s NPM package:
The NPM package is optional for most Laravel applications. You only need it if you’re:
  • Building an SPA with a separate frontend repository
  • Not using the @routes Blade directive
  • Importing Ziggy directly in JavaScript modules

Basic Setup

Adding the @routes Directive

The simplest way to use Ziggy is to add the @routes Blade directive to your main layout file. This makes the route() function available globally in your JavaScript. Add the directive in your layout’s <head> section, before your application’s JavaScript:
The @routes directive must be placed before your JavaScript files to ensure the route configuration is available when your scripts load.

What @routes Does

The @routes directive outputs:
  1. Your application’s base URL and configuration
  2. A list of all named routes with their URIs, methods, and parameters
  3. The Ziggy JavaScript route() helper function
Example output:

Verifying Installation

1

Create a Test Route

Add a simple named route to your routes/web.php:
2

Use route() in JavaScript

Open your browser’s console on any page and test the route() function:
3

Check Available Routes

List all available routes:
If route('test') returns a URL, Ziggy is installed correctly!

Configuration (Optional)

Ziggy works out of the box without any configuration. However, you can customize its behavior by publishing the configuration file:
This creates a config/ziggy.php file with the following options:
config/ziggy.php
only: Array of route patterns to include (e.g., ['posts.*', 'users.show'])except: Array of route patterns to exclude (e.g., ['admin.*', '_debugbar.*'])groups: Named groups of routes that can be included on specific pagesoutput.path: Where to generate the routes file when using php artisan ziggy:generate

Alternative Setup Methods

For JavaScript Frameworks (Vue, React)

If you’re building an SPA or prefer to import Ziggy in your JavaScript modules:
1

Generate the Routes File

Run the Artisan command to generate a JavaScript routes file:
This creates resources/js/ziggy.js with your route configuration.
2

Import in Your JavaScript

For SPAs or Separate Repositories

If your frontend is completely separate from your Laravel backend:
1

Install NPM Package

2

Generate Routes File

Run the command in your Laravel app:
Copy the generated file to your frontend project.
3

Or Create API Endpoint

Alternatively, create an API endpoint to fetch routes:
routes/api.php

TypeScript Support

Ziggy includes TypeScript type definitions. To enable route name autocompletion:
This generates type definitions for all your routes. Add this to a .d.ts file:
types/ziggy.d.ts

Next Steps

Quickstart Guide

Build your first Ziggy-powered feature in minutes

Usage Examples

Learn all the ways to use the route() function