PHPackages                             spatian-dev/ziglite - 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. spatian-dev/ziglite

AbandonedArchivedLibrary

spatian-dev/ziglite
===================

A Laravel named routes integration for Javascript

v1.2.0(1y ago)217Apache-2.0TypeScriptPHP ^8.1

Since Apr 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/spatian-dev/ziglite)[ Packagist](https://packagist.org/packages/spatian-dev/ziglite)[ Docs](https://ziglite.spatian.dev)[ RSS](/packages/spatian-dev-ziglite/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

Ziglite - A Laravel named routes integration for Javascript
===========================================================

[](#ziglite---a-laravel-named-routes-integration-for-javascript)

[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/dfb196e2d4c47806d7d9038827773228b15fd5a4efcafbe69db63c973c072054/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469616e2d6465762f7a69676c6974652f746573742e79616d6c3f6c6162656c3d4275696c64266272616e63683d312e78)](https://camo.githubusercontent.com/dfb196e2d4c47806d7d9038827773228b15fd5a4efcafbe69db63c973c072054/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469616e2d6465762f7a69676c6974652f746573742e79616d6c3f6c6162656c3d4275696c64266272616e63683d312e78)[![Packagist Version](https://camo.githubusercontent.com/62c3185ac138cb282ebd8059648d2f40d61efbcce68a52c7f6f4414c87a893db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469616e2d6465762f7a69676c6974653f6c6162656c3d5061636b6167697374)](https://camo.githubusercontent.com/62c3185ac138cb282ebd8059648d2f40d61efbcce68a52c7f6f4414c87a893db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469616e2d6465762f7a69676c6974653f6c6162656c3d5061636b6167697374)[![Packagist Downloads](https://camo.githubusercontent.com/cebb29e18ab3e49a049993be0db837b3de6124b53b7717042dffbeedf6667ea8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469616e2d6465762f7a69676c6974653f6c6162656c3d5061636b6167697374253230646f776e6c6f616473)](https://camo.githubusercontent.com/cebb29e18ab3e49a049993be0db837b3de6124b53b7717042dffbeedf6667ea8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469616e2d6465762f7a69676c6974653f6c6162656c3d5061636b6167697374253230646f776e6c6f616473)[![NPM Version](https://camo.githubusercontent.com/891bfad328b8bed922ac83164dc04678c08a4b82bf0885926a0e366e923f3921/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f7a69676c6974653f6c6162656c3d4e504d)](https://camo.githubusercontent.com/891bfad328b8bed922ac83164dc04678c08a4b82bf0885926a0e366e923f3921/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f7a69676c6974653f6c6162656c3d4e504d)[![NPM Downloads](https://camo.githubusercontent.com/9e1377f2b8235bbdf13a7e6630613a229e4a1d2d59714dd5c0c748ceab2d1c4a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6431386d2f7a69676c6974653f6c6162656c3d4e504d253230646f776e6c6f616473)](https://camo.githubusercontent.com/9e1377f2b8235bbdf13a7e6630613a229e4a1d2d59714dd5c0c748ceab2d1c4a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6431386d2f7a69676c6974653f6c6162656c3d4e504d253230646f776e6c6f616473)

What is Ziglite?
----------------

[](#what-is-ziglite)

[Ziglite](https://ziglite.spatian.dev) provides a way for Laravel developers to use their route names in the front end.
This package is inspired by, and a lightweight minimalistic alternative to, the excellent and feature-rich [Ziggy](https://github.com/tighten/ziggy) by [Tighten](https://tighten.com/).

- **[Quick Start](#quick-start)**
- **[Supported Laravel Versions](#supported-laravel-versions)**
- **[Why Ziglite?](#why-ziglite)**
- **[Usage in a Package](#usage-in-a-package)**
- **[Route Filtering](#route-filtering)**
- **[The Routes Manifest](#the-routes-manifest)**
    - [Filters](#filters)
    - [Custom Origin](#custom-origin)
    - [Caching](#caching)
    - [Serializing to JSON](#serializing-to-json)
- **[The Blade Directive](#the-blade-directive)**
    - [Custom Directives and Custom Generators](#custom-directives-and-custom-generators)
- **[The Front-end Helpers](#the-front-end-helpers)**
    - [The `configureRouter()` helper](#the-configurerouter-helper)
    - [The `route()` and `hasRoute()` helpers](#the-route-and-hasroute-helpers)
    - [Default Parameters](#default-parameters)
    - [Generating Absolute URLs](#generating-absolute-urls)
    - [Extra Query Parameters](#extra-query-parameters)
    - [The Router Class](#the-router-class)
    - [Strict Mode](#strict-mode)
- **[Contributing](#contributing)**
- **[Credits](#credits)**
- **[License](#license)**

Quick Start
-----------

[](#quick-start)

Install Ziglite in your Laravel application or package with Composer:

```
composer require spatian-dev/ziglite
yarn install ziglite
```

Include the default directive in your Blade `@ziglite("*")`:

> **⚠️Warning:** This will expose all the named routes and their parameters in your application to the front-end, which may not be desirable.
> See [Route filtering](#route-filtering) to learn about including and excluding routes.

Configure the javascript helpers:

```
import { configureRouter } from 'ziglite';
configureRouter(ziglite_data);
```

Use the `route()` helper to transform a named route to a URL:

```
import { route } from 'ziglite';
route('users.update', {user: 5});
```

> **⚠️Warning:** Ziglite does not support [Encoded Forward Slashes](https://laravel.com/docs/11.x/routing#parameters-encoded-forward-slashes). See [strict mode](#strict-mode) for more information.

Supported Laravel Versions
--------------------------

[](#supported-laravel-versions)

LaravelSupported10.x✅11.x✅Why Ziglite?
------------

[](#why-ziglite)

Ziglite is intended to be a simplified alternative to Ziggy. By omitting some of Ziggy's more advanced features, Ziglite offers a focused feature set aimed at ease of use. One notable difference is in filtering: Ziglite opts for a simplified and stricter approach by default.

Additionally, Ziglite boasts seamless integration into Laravel packages, providing developers with the ability to:

- Define custom aliases for the default Blade directive
- Utilize custom output generators
- Exert greater control over route filtering.

We hope Ziglite delivers simplicity and versatility for your Laravel projects and packages.
If you have ideas or suggestions, please see [Contributing](#contributing).

Usage in a Package
------------------

[](#usage-in-a-package)

Register Ziglite's service provider inside the `register()` method of your package's service provider:

```
$this->app->register(\Spatian\Ziglite\Providers\ZigliteServiceProvider::class);
```

You can then use the package the same way you would from a regular Laravel Application.

Route Filtering
---------------

[](#route-filtering)

Ziglite only includes named routes that match explicitly provided filters. The filtering is based on [pattern-matching capabilities provided by Laravel's Str helper](https://laravel.com/docs/11.x/strings#method-str-is).

Exclusion can be defined by starting the pattern with a `!`

> **ℹ️** Exclusions patterns are always prioritized over inclusion patterns, regardless of the order in which they are defined.

For example:

- `*` will include all named routes
- `!users.*` will exclude all named routes starting with `users.`
- `!*.index` will exclude all named routes ending with `.index`
- `home` will include the route named `home`

You can provide as many inclusion or exclusion patterns as necessary

```
use Spatian\Ziglite\Routes\Manifest;

new Manifest(["*", "!admin.*", "!api.*"]);

// in blade
@ziglite(["*", "!admin.*", "!api.*"]);
```

The Routes Manifest
-------------------

[](#the-routes-manifest)

The core of Ziglite revolves around the [`\Spatian\Ziglite\Routes\Manifest`](src/Routes/Manifest.php) class. This class collects and caches your application's named routes, and generates a list of named routes that match the provided filters.

### Filters

[](#filters)

By default, a `Manifest` instance will only include named routes that match the provided filters. If no filters are provided, then no routes are included.
Filtering patterns can be provided as the first argument to the constructor.

```
use Spatian\Ziglite\Routes\Manifest;

new Manifest(); // No routes included

new Manifest("*"); // A single pattern
new Manifest(["*", "!admin.*", "!api.*"]); // A list of patterns
```

See [Route filtering](#route-filtering) to learn more about filtering.

### Custom Origin

[](#custom-origin)

You can specify a custom origin to be included in the manifest.

```
use Spatian\Ziglite\Routes\Manifest;

new Manifest(base: 'https://example.test');
```

### Caching

[](#caching)

The `Manifest` class caches previously generated manifests for the duration of a request. Subsequent calls with the same filtering patterns simply return the previously calculated result.
If this is not desirable, you can clear this cache using :

```
use Spatian\Ziglite\Routes\Manifest;

Manifest::clearRoutes();
```

### Serializing to JSON

[](#serializing-to-json)

The `Manifest` class implements [`JsonSerializable`](https://www.php.net/manual/en/class.jsonserializable.php) and a `toJson()` function to simplify serializing to JSON.

```
use Spatian\Ziglite\Routes\Manifest;

json_encode(new Manifest());
(new Manifest())->toJson();
```

The Blade Directive
-------------------

[](#the-blade-directive)

By default, Ziglite defines a `@ziglite` blade directive. This directive uses the default [`JavascriptDataTagGenerator`](src/Generators/JavascriptDataTagGenerator.php) to include a manifest as a JSON object in a blade.
The JSON object is assigned to a `ziglite_data` variable on the `window` global.

```
// home.blade.php
@ziglite("*")
```

```
// home.js
console.log(ziglite_data);
/*
    Should print an object similar to :

    {
        base: ...,
        defaults: { ... },
        routes: [ ... ],
    }
*/
```

### Custom Directives and Custom Generators

[](#custom-directives-and-custom-generators)

You can define your custom generators by implementing the [`OutputGeneratorInterface`](src/Interfaces/OutputGeneratorInterface.php). This requires implementing a `make()` function that generates the output as a string.

```
make(array|string $filters = [], string $base = null, string $nonce = ''): string
```

- `$filters` pattern or list of patterns for [filtering](#route-filtering)
- `$base` [custom origin](#custom-origin) to be included in the output
- `$nonce` a [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) nonce to be included in the output.

You can also define a custom blade directive that uses your custom generator. In your `AppServiceProvider`:

```
app('ziglite')->setupBladeDirective('mydirective', new MyCustomOutputGenerator());
```

The Front-end Helpers
---------------------

[](#the-front-end-helpers)

The javascript library is published to a separate NPM package.

```
yarn install ziglite
```

By default, Ziglite does not globally import its javascript helpers. Instead, it defers to the developer to include them and use them as they see fit.
The library does, however, create an internal default instance of [the `Router` class](#the-router-class). You can interact with this instance through the helper functions below.

### The `configureRouter()` helper

[](#the-configurerouter-helper)

Use this function to set the configuration for the default `Router` instance.

```
import { configureRouter } from 'ziglite';

configureRouter(ziglite_data);

configureRouter({
    strict: false,
    absolute: true,
    base: 'https://example.test',
});
```

### The `route()` and `hasRoute()` helpers

[](#the-route-and-hasroute-helpers)

The `route()` function transforms a named route to a URL using the default `Router` instance. This function works similarly to Laravel's `route()`.

```
import { route } from 'ziglite';

route('home');

route('users.show', {user: 5});
```

The `hasRoute()` function checks if the default `Router` instance has a configured route that matches the given name.

```
import { hasRoute } from 'ziglite';

hasRoute('home');   // assuming a route named 'home' exits, return true;
hasRoute('inexistant');   // assuming no route named 'inexistant' exits, return false;
```

### Default Parameters

[](#default-parameters)

Ziglite supports [Laravel's default parameters](https://laravel.com/docs/11.x/urls#default-values).

```
import { route } from 'ziglite';
/*
    Given a route named 'users.show' defined as /{locale}/users/{user},
    and configured route default ['locale' => 'en']
*/
route('users.show', {user: 5}); // https://example.test/en/users/5
```

### Generating Absolute URLs

[](#generating-absolute-urls)

By default, Ziglite will generate relative URLs. To generate absolute URLs instead, set the `absolute` configuration to `true`;

```
import { configureRouter, route } from 'ziglite';

configureRouter({
    absolute: true,
    base: 'https://example.test',
    // ...
});

route('users.show', {user: 5}); // https://example.test/users/5
```

### Extra Query Parameters

[](#extra-query-parameters)

Ziglite will automatically add any unmatched parameters as a query string to the resulting URL:

```
import { route } from 'ziglite';

route('users.show', {user: 5, extra: 2}); // https://example.test/users/5?extra=2
```

If you need to add query-string parameters that have the same name as your route's parameter, you can do so under a `_query` object:

```
import { route } from 'ziglite';

route('users.show', {
    user: 5,
    extra: 2,
    _query: {
        user: 'Tony'
    },
}); // https://example.test/users/5?extra=2&user=Tony
```

By default, booleans are converted to integers

```
import { route } from 'ziglite';

route('users.show', {
    user: 5,
    locked: true,
}); // https://example.test/users/5?locked=1
```

### The Router Class

[](#the-router-class)

The [`Router`](js/classes/Router.ts) provides the core of Ziglite's javascript functionality.
If you would like to use Ziglite's features without modifying the default instance, you might create your own `Router` instance:

```
import { Router } from 'ziglite';

const config = {
    absolute: true,
    base: 'https://example.test',
    defaults: {
        locale: 'en',
    },
    routes: [ /* ... */],
};

const myRouter = new Router();
myRouter.config = config;

// or
const myRouter = new Router(config);

// check if the given named route exists
myRouter.has('home');

// transform the given named route and parameters to a URL
myRouter.compile('users.show', {user: 5}); // https://example.test/users/5
```

### Strict Mode

[](#strict-mode)

Ziglite does not support [Encoded Forward Slashes](https://laravel.com/docs/11.x/routing#parameters-encoded-forward-slashes). This has historically been buggy, inconsistent and overall not a reliable feature to implement.
By default, Ziglite will issue a warning in your console if it encounters a forward slash, plain (`/`) or encoded (`%2F`), in a parameter value.
If you enable strict mode, Ziglite will throw an error instead.

```
import { configureRouter, route } from 'ziglite';

configureRouter({
    strict: true,
    // ...
});

route('users.show', {user: 'test/test'}); // throws
```

Contributing
------------

[](#contributing)

Please consult the [contribution guide](CONTRIBUTING.md).

Credits
-------

[](#credits)

- This package is heavily inspired by the excellent and feature-rich [Ziggy](https://github.com/tighten/ziggy) by [Tighten](https://tighten.com/). Shout out to them.
- [Saad Sidqui](https://github.com/saadsidqui)
- [All the contributors](https://github.com/spatian-dev/ziglite/graphs/contributors)

License
-------

[](#license)

Ziglite is free and open-source software released under the Apache 2.0 license. See [LICENSE](LICENSE) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance40

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~66 days

Total

5

Last Release

510d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f258e205fa7d40cc892980012cfd1c64663ea99fa7854fa2a9d8080661796006?d=identicon)[spatian](/maintainers/spatian)

---

Top Contributors

[![saadsidqui](https://avatars.githubusercontent.com/u/25284407?v=4)](https://github.com/saadsidqui "saadsidqui (29 commits)")

---

Tags

javascriptlaravellaravel-packagenamed-routeslaravelroutespackagelaravel-packageroutingnamedziglite

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatian-dev-ziglite/health.svg)

```
[![Health](https://phpackages.com/badges/spatian-dev-ziglite/health.svg)](https://phpackages.com/packages/spatian-dev-ziglite)
```

###  Alternatives

[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[onramplab/laravel-custom-fields

An laravel package that enables custom field support for any Laravel models

103.9k](/packages/onramplab-laravel-custom-fields)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
