PHPackages                             pushery/polyslug-for-laravel - 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. [Database &amp; ORM](/categories/database)
4. /
5. pushery/polyslug-for-laravel

ActiveLibrary[Database &amp; ORM](/categories/database)

pushery/polyslug-for-laravel
============================

Polymorphic, multilingual routable identity for Eloquent — leak-safe IDs, per-locale slugs, and hreflang out of the box.

v0.8.1(2w ago)62.4k↑450%MITPHPPHP ^8.4

Since Jul 5Pushed 2w agoCompare

[ Source](https://github.com/pushery/polyslug-for-laravel)[ Packagist](https://packagist.org/packages/pushery/polyslug-for-laravel)[ Docs](https://github.com/pushery/polyslug-for-laravel)[ RSS](/packages/pushery-polyslug-for-laravel/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (51)Versions (17)Used By (0)

 [ ![Polyslug](art/header.png) ](https://github.com/pushery/polyslug-for-laravel)

Polyslug
========

[](#polyslug)

[![Latest Version](https://camo.githubusercontent.com/08bf942d261187b18a7e4d81b0a0a3fe6cc02a717c442fdc4fef57a70838f53b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f707573686572792f706f6c79736c75672d666f722d6c61726176656c2e737667)](https://packagist.org/packages/pushery/polyslug-for-laravel)[![PHP Version](https://camo.githubusercontent.com/9437d26ebf90d45727085e02ac61aac206f8c42becb88b1d27a06e7c184f30ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f707573686572792f706f6c79736c75672d666f722d6c61726176656c2f7068702e737667)](https://packagist.org/packages/pushery/polyslug-for-laravel)[![Laravel Versions](https://camo.githubusercontent.com/6698e8e65778e765424d91adec678eafa951549f4c16ed2415ab44d9709d9054/68747470733a2f2f62616467652e6c61726176656c2e636c6f75642f62616467652f707573686572792f706f6c79736c75672d666f722d6c61726176656c3f7374796c653d666c6174)](https://packagist.org/packages/pushery/polyslug-for-laravel)[![PHPStan](https://camo.githubusercontent.com/c47b2ba3238269b2d6f0e8c346934f4e94ee7ff7345c2738e62830182711717f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d626c75652e737667)](https://phpstan.org)[![Code Style](https://camo.githubusercontent.com/d1e49fbc2c712416be5a417fd3a8d339062c657ecbe46e4ada4dd0156dfd325f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d70696e742d6f72616e67652e737667)](https://laravel.com/docs/pint)[![License](https://camo.githubusercontent.com/c7dde3b195c46e6998dc2c7671c7fe401936d6d1098b13585a11be71568d25f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f707573686572792f706f6c79736c75672d666f722d6c61726176656c2e737667)](LICENSE)

**Polymorphic, multilingual routable identity for Eloquent.** Pretty URLs that are safe to expose, safe to rename, and correct across languages — with leak-free IDs, self-healing canonical redirects, and hreflang built in.

```
/blog/laravel-routing-explained_aB3xK
      └──────── slug ─────────┘ └id─┘
   changeable, localized, SEO-friendly   stable, opaque, resolves the model

```

A slug should be free to change. A URL should never break. Those two goals usually fight each other. Polyslug settles the fight by splitting a URL into two independent parts — a **human-readable slug** (pretty, per-locale, editable) and a **stable opaque identity** (an encoded token that resolves the model). Rename the slug all you like: the identity still resolves, and old URLs redirect themselves to the new canonical one.

---

Install
-------

[](#install)

```
composer require pushery/polyslug-for-laravel
php artisan migrate
```

Mark a model as sluggable, point a route at it, and you are done:

```
#[Polyslug(source: 'title')]
class Page extends Model implements Sluggable
{
    use HasPolyslug;
}

Route::polyslug('/pages/{page}', [PageController::class, 'show'])->name('pages.show');
```

Rename the page and the old URL `301`s to the new one, by itself.

Why Polyslug?
-------------

[](#why-polyslug)

- 🔒 **Leak-safe IDs by default.** URLs carry an encoded token, not `/pages/1523`. No exposed row counts, no enumerable primary keys. The default encoder issues a random, unguessable token per row — the only shipped encoder that makes that claim true end to end. The choice is yours, though: Sqids, UUID, ULID, the raw key, or your own.
- ♻️ **Self-healing URLs.** Rename freely. A stale slug on a `GET`/`HEAD` request is `301`-redirected to the current canonical URL automatically — no redirect tables to hand-maintain, no dead links, no lost link equity.
- 🌍 **Multilingual with hreflang out of the box.** One slug per locale, and a reciprocal `hreflang` set (plus `x-default`) generated from the **same** resolver that builds your canonical URL — so they can never drift apart.
- 🧩 **Polymorphic routing.** Serve every content type — pages, articles, products — through a single `{type}/{polyslug}` route and one registry.
- 🧭 **Stable resolution.** Route-model binding decodes the identity, not the slug, so a mistyped or outdated slug still finds the right model (then redirects). An unknown or malformed token is a clean `404` — never a fuzzy match.
- 🏢 **Scoped uniqueness.** Uniqueness can be scoped per tenant, per locale, per category — whatever columns you name.
- 🗂️ **History, events &amp; immutability.** Superseded slugs are kept so old URLs keep resolving; a `SlugChanged` event fires on every change; slugs can be frozen.
- 🤝 **Writes its own `` via `laravel/head`.** Install Laravel's `` package and `Head::polyslug($model)` fills in the canonical URL, the `hreflang` set, the Open Graph locales and a `robots` directive for models your visibility gate hides. Optional — Polyslug requires nothing beyond slim `illuminate/*` components either way.
- ✅ **Proven on the databases you deploy to.** The one-current-slug guarantee ships as a functional partial unique index on PostgreSQL and SQLite and as generated key columns on MySQL — two genuinely different mechanisms, and the suite proves both against real PostgreSQL 18 and MySQL 8.4 servers rather than inferring one from the other.

Documentation
-------------

[](#documentation)

**Full docs at [docs.pushery.com/polyslug-for-laravel](https://docs.pushery.com/polyslug-for-laravel/).**

- [Installation](https://docs.pushery.com/polyslug-for-laravel/installation) — requirements, the migration, publishing
- [Quick start](https://docs.pushery.com/polyslug-for-laravel/quick-start) — a sluggable model and a self-healing route
- [Features](https://docs.pushery.com/polyslug-for-laravel/features) — encoders, hreflang, nested paths, sitemaps, short links
- [laravel/head](https://docs.pushery.com/polyslug-for-laravel/features/laravel-head) — canonical URL, hreflang and indexability in Laravel's `` package
- [Recipes](https://docs.pushery.com/polyslug-for-laravel/recipes) — twelve app shapes wired end to end
- [Reference](https://docs.pushery.com/polyslug-for-laravel/reference/configuration) — every config key, option, command, event and contract

Requirements
------------

[](#requirements)

- PHP 8.4+
- Laravel 13+
- PostgreSQL, MySQL 8.4+, or SQLite — the uniqueness guarantees are enforced natively on each, and the full suite runs against all three. So Polyslug works on Laravel Cloud (serverless Postgres + MySQL 8.4 LTS) with no extra configuration.

Security
--------

[](#security)

Please review the [security policy](SECURITY.md) and report vulnerabilities privately rather than opening a public issue.

Built by Pushery
----------------

[](#built-by-pushery)

This package is built and maintained by [Pushery](https://www.pushery.com) — a Berlin-based studio building Laravel applications, SaaS products, and open-source tools.

Building a Laravel UI? [WireKit](https://wirekit.app), Pushery's open-source Livewire component kit, gives you a polished component library out of the box. Browse the rest of our work at [pushery.com](https://www.pushery.com).

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance96

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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 ~2 days

Total

16

Last Release

18d ago

### Community

Maintainers

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

---

Top Contributors

[![pushery](https://avatars.githubusercontent.com/u/272318911?v=4)](https://github.com/pushery "pushery (16 commits)")

---

Tags

canonical-urlseloquenthreflangi18nlaravellaravel-packagelocalizationmodel-routingmultilanguagepolymorphicpretty-urlsredirectroutingseoslugslugsurlurlslaravel

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/pushery-polyslug-for-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/pushery-polyslug-for-laravel/health.svg)](https://phpackages.com/packages/pushery-polyslug-for-laravel)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M332](/packages/laravel-ai)[illuminate/queue

The Illuminate Queue package.

20433.0M1.8k](/packages/illuminate-queue)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

265.2k](/packages/aedart-athenaeum)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M163](/packages/laravel-cashier)

PHPackages © 2026

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