Polyscope - The agent-first dev environment for Laravel

Ziggy

tightenco/ziggy image

Ziggy stats

Downloads
12.4M
Stars
3,419
Open Issues
4
Forks
253

View on GitHub →

Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.

Ziggy – Use Your Laravel Routes in JavaScript

Ziggy is a Laravel package designed to make Laravel's named routes accessible in JavaScript, providing a seamless way to generate URLs based on your routes directly from your client-side scripts. It's compatible with Laravel version 5.4 and up, and supports all modern browsers.

Key Features:

  • JavaScript Route Helper: Mimics Laravel's PHP route() helper, allowing you to generate URLs for your named routes in JavaScript.
  • Support for Route Parameters: Pass parameters to your routes just like you do in Laravel, including support for route-model binding.
  • Integration with JavaScript Frameworks: Works out-of-the-box with popular frameworks like Vue and React, including a Vue plugin and a React hook.
  • TypeScript Support: Comes with unofficial TypeScript definitions to help integrate with TypeScript projects.
  • Advanced Route Filtering: Provides options to filter which routes are made available to your JavaScript, optimizing load times and enhancing security.
  • Flexible Setup Options: Can be used with the Blade directive or via an API endpoint, making it adaptable to various application architectures including SPAs.

Installation:

  1. Add Ziggy to your Laravel project:
    composer require tightenco/ziggy
  2. Include the @routes Blade directive in your main layout file, before any JavaScript is loaded.

Usage:

  • Generating URLs:
    route('posts.show', { id: 1 }); // Generates URL for the posts.show route with id 1
  • Accessing Route Functions: When called with no arguments, route() returns a Router instance, allowing access to methods like current(), has(), and properties like params.

Advanced Setup:

  • Non-Blade Environments: Use php artisan ziggy:generate to create a routes file, or configure an endpoint to provide route configuration as JSON.
  • Framework Integration:
    • Vue: Use the ZiggyVue plugin for easy integration.
    • React: Utilize the useRoute() hook for seamless route generation.

Practical Considerations:

  • Security with Content Security Policies (CSP): If using CSP, pass a nonce to the @routes directive to enable inline script execution.
  • TLS/SSL Termination: Ensure proper proxy configuration to prevent URL scheme mismatches in generated URLs.

Contributing:

Contributors are welcome! Check the GitHub repository for issues that need help.

License:

Ziggy is open-source software licensed under the MIT license.

For comprehensive details on setup and usage, refer to the package's full documentation and GitHub repository.

tighten photo

We're not here anymore! We're at github.com/tighten


Tightenco Ziggy Related Articles

Ziggy: A Package for Named Laravel Routes in JavaScript image

Ziggy: A Package for Named Laravel Routes in JavaScript

Read article
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media