PHPackages                             amrikasir/ziggy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. amrikasir/ziggy

AbandonedArchivedLibrary[API Development](/categories/api)

amrikasir/ziggy
===============

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

0.7.2(6y ago)084MITJavaScript

Since Aug 13Pushed 4y agoCompare

[ Source](https://github.com/amrikasir/ziggy)[ Packagist](https://packagist.org/packages/amrikasir/ziggy)[ RSS](/packages/amrikasir-ziggy/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

> just a copy/fork from [tightenco/ziggy](https://github.com/tightenco/ziggy).

> since I need Ziggy with features that I added for my Laravel Project and tightenco response is too long, I'll re-post new Packagist repository

[![Ziggy - Use your Laravel Named Routes inside JavaScript](https://raw.githubusercontent.com/tightenco/ziggy/master/ziggy-banner.png?version=2)](https://raw.githubusercontent.com/tightenco/ziggy/master/ziggy-banner.png?version=2)

Ziggy - Use your Laravel Named Routes inside JavaScript
=======================================================

[](#ziggy---use-your-laravel-named-routes-inside-javascript)

Ziggy creates a Blade directive which you can include in your views. This will export a JavaScript object of your application's named routes, keyed by their names (aliases), as well as a global `route()` helper function which you can use to access your routes in your JavaScript.

Installation
------------

[](#installation)

1. Add Ziggy to your Composer file: `composer require amrikasir/ziggy` or `composer -vvv require amrikasir/ziggy` if you want to see verbose log
2. (if Laravel 5.4) Add `Tightenco\Ziggy\ZiggyServiceProvider::class` to the `providers` array in your `config/app.php`.
3. Include our Blade Directive (`@routes`) somewhere in your template before your main application JavaScript is loaded—likely in the header somewhere.

Usage
-----

[](#usage)

This package replaces the `@routes` directive with a collection of all of your application's routes, keyed by their names. This collection is available at `Ziggy.namedRoutes`.

The package also creates an optional `route()` JavaScript helper which functions like Laravel's `route()` PHP helper, which can be used to retrieve URLs by name and (optionally) parameters.

### Examples:

[](#examples)

Without parameters:

```
route('posts.index') // Returns '/posts'
```

With required parameter:

```
route('posts.show', {id: 1}) // Returns '/posts/1'
route('posts.show', [1]) // Returns '/posts/1'
route('posts.show', 1) // Returns '/posts/1'
```

With multiple required parameters:

```
route('events.venues.show', {event: 1, venue: 2}) // Returns '/events/1/venues/2'
route('events.venues.show', [1, 2]) // Returns '/events/1/venues/2'
```

With query parameters:

```
route('events.venues.show', {event: 1, venue: 2, page: 5, count: 10})
// Returns '/events/1/venues/2?page=5&count=10'
```

If whole objects are passed, Ziggy will automatically look for `id` primary key:

```
var event = {id: 1, name: 'World Series'};
var venue = {id: 2, name: 'Rogers Centre'};

route('events.venues.show', [event, venue]) // Returns '/events/1/venues/2'
```

If want to use unamed route like

```
url('/url/want/to/go');
```

Ziggy privide `go` method:

```
route().go('/url/want/to/go')
```

Practical AJAX or Axios example:

```
var post = {id: 1, title: 'Ziggy Stardust'};

return axios.get(route('posts.show', post))
    .then((response) => {
        return response.data;
    });
```

Ajax or Axios with unamed route

```
return axios.get(route().go('/url/want/to/go'))
    .then((response) => {
        return response.data;
    });
```

### Default Values

[](#default-values)

See Laravel [documentation](https://laravel.com/docs/5.5/urls#default-values)

Default values work out of the box for Laravel versions &gt;= 5.5.29, for the previous versions you will need to set the default parameters by including this code somewhere in the same page as our Blade Directive (@routes)

```
Ziggy.defaultParameters = {
    //example
    locale: "en"
}
```

Filtering Routes
----------------

[](#filtering-routes)

Filtering routes is *completely* optional. If you want to pass all of your routes to JavaScript by default, you can carry on using Ziggy as described above.

### Basic Whitelisting &amp; Blacklisting

[](#basic-whitelisting--blacklisting)

To take advantage of basic whitelisting or blacklisting of routes, you will first need to create a standard config file called `ziggy.php` in the `config/` directory of your Laravel app and set **either** the `whitelist` or `blacklist` setting to an array of route names.

**Note: You've got to choose one or the other. Setting `whitelist` and `blacklist` will disable filtering altogether and simply return the default list of routes.**

#### Example `config/ziggy.php`:

[](#example-configziggyphp)

```
