tightenco/ziggy
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
laravel/framework | v5.8.38 | 1.06 MB | MIT | prod | 6 |
Tightenco/Ziggy is a versatile Laravel package that creates a Blade directive for exporting all your named Laravel routes, effectively bridging the gap between your Laravel backend and JavaScript frontend. The central tool it provides is a handy route()
helper function that works just like Laravel's own, allowing you to use your Laravel named routes in JavaScript. By leveraging Ziggy, developers can seamlessly generate URLs for named routes, utilize parameters, and even apply route-model binding right from their JavaScript files. This makes the package particularly beneficial for projects that extensively incorporate AJAX requests and front-end frameworks, or when Laravel is used as a backend for an SPA or mobile application.
To use the Tightenco/Ziggy package, first, install it in your Laravel app using composer:
composer require tightenco/ziggy
Then, add the @routes
Blade directive to your main layout. This should come before your application's JavaScript to ensure the route()
helper function is globally available:
// In your blade layout file
<head>
...
@routes
<script src="{{ mix('js/app.js') }}"></script>
</head>
You can now utilize Ziggy’s route()
helper function in your JavaScript files. The route()
helper works very much like Laravel's—you pass to it a route name, and any parameters you wish to send, and it will return a URL:
// Basic usage with no parameters
route('posts.index'); // returns 'https://your-domain.com/posts'
// Usage with parameters
route('posts.show', 1); // returns 'https://your-domain.com/posts/1'
Refer to the complete documentation in the Github ReadMe for advanced usage, setting up with different frameworks, route filtering options, and troubleshooting.
The documentation for Tightenco/Ziggy is available on the project's Github ReadMe page at https://github.com/tighten/ziggy. The ReadMe contains detailed usage and setup instructions, examples, advanced setup options, and more. The documentation covers everything from installation to handling route filtering and working with different JavaScript frameworks. It is regularly updated to accommodate changes in the Laravel ecosystem and the evolving needs of developers. By referring to this documentation, developers can maximize the benefits of integrating their Laravel routes with JavaScript front-end.