PHPackages                             spatie/laravel-sluggable - 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. spatie/laravel-sluggable

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

spatie/laravel-sluggable
========================

Generate slugs when saving Eloquent models

4.0.2(2mo ago)1.6k12.9M↓18.8%19020MITPHPPHP ^8.3CI passing

Since Dec 24Pushed 1mo ago16 watchersCompare

[ Source](https://github.com/spatie/laravel-sluggable)[ Packagist](https://packagist.org/packages/spatie/laravel-sluggable)[ Docs](https://github.com/spatie/laravel-sluggable)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-sluggable/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (10)Dependencies (17)Versions (68)Used By (20)

 [   ![Logo for laravel-sluggable](https://camo.githubusercontent.com/38b7e7533fb081b6e506a2658382d3dd7f69b9b3adc1b232c62eaec905577f42/68747470733a2f2f7370617469652e62652f7061636b616765732f6865616465722f6c61726176656c2d736c75676761626c652f68746d6c2f6c696768742e77656270)  ](https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-sluggable)Generate slugs when saving Eloquent models
==========================================

[](#generate-slugs-when-saving-eloquent-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/04e459a472439650ccfa5aaee0b9a05ceaaa02140ce809f4cda60c1ca188d7f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d736c75676761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-sluggable)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://github.com/spatie/laravel-sluggable/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-sluggable/actions)[![Total Downloads](https://camo.githubusercontent.com/a6ebf5dcacdaed45b2a78019c976252e12f761adeb23d0ab8c2fccfe2d2673a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d736c75676761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-sluggable)

This package generates a unique slug for any Eloquent model whenever it is created or updated. Add a `#[Sluggable]` attribute to the model and the package handles the rest.

```
use Spatie\Sluggable\Attributes\Sluggable;

#[Sluggable(from: 'title', to: 'slug')]
class Post extends Model
{
}

$post = Post::create(['title' => 'activerecord is awesome']);
$post->slug; // "activerecord-is-awesome"
```

For features that need closures (custom source callables, scoped uniqueness, conditional skip, custom suffix generators) use the `HasSlug` trait with a `getSlugOptions()` method instead.

Highlights
----------

[](#highlights)

- **Unique slugs out of the box**, with a configurable `-1`, `-2`, ... suffix on collisions.
- **Self-healing URLs**: route keys that combine the slug with the primary key (`hello-world-5`) so renaming a model never breaks an existing link. Stale slugs return a `308` redirect to the canonical URL.
- **Translatable slugs** through `HasTranslatableSlug` and `spatie/laravel-translatable`.
- **Overridable actions**: swap the slug generator or the self-healing URL logic for your own class via a config file.
- **Laravel Boost skill** bundled with the package, so AI assistants know how to scaffold sluggable models in your project. Boost discovers it automatically once both packages are installed.

Self-healing URLs combine the slug with the primary key. The `HasSlug` trait is required alongside the attribute, because it overrides Eloquent's route key and route binding methods.

```
#[Sluggable(from: 'title', to: 'slug', selfHealing: true)]
class Post extends Model
{
    use HasSlug;
}

// /posts/hello-world-5   → 200
// /posts/old-title-5     → 308 to /posts/hello-world-5
```

Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/ba59ca0eae3b9a4517a003d1373e3b81707928de3640334ea57204039f0a1872/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d736c75676761626c652e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-sluggable)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#documentation)

All documentation is available [on our documentation site](https://spatie.be/docs/laravel-sluggable).

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

[](#installation)

```
composer require spatie/laravel-sluggable
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

81

—

ExcellentBetter than 100% of packages

Maintenance91

Actively maintained with recent releases

Popularity73

Solid adoption and visibility

Community53

Growing community involvement

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 61.9% 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 ~61 days

Recently: every ~2 days

Total

63

Last Release

66d ago

Major Versions

1.5.1 → 2.0.02017-08-30

1.5.2 → 2.1.42018-08-28

2.6.2 → 3.0.02021-03-26

3.8.1 → v4.x-dev2026-04-21

v3.x-dev → 4.0.12026-04-29

PHP version history (8 changes)0.0.1PHP &gt;=7.0.0

2.1.7PHP &gt;=7.1.3

2.2.0PHP ^7.2

2.3.0PHP ^7.4

2.6.0PHP ^7.4|^8.0

3.0.0PHP ^8.0

3.8.0PHP ^8.2

v4.x-devPHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (267 commits)")[![marvin-wtt](https://avatars.githubusercontent.com/u/31454580?v=4)](https://github.com/marvin-wtt "marvin-wtt (26 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (15 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (11 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (11 commits)")[![joshuadegier](https://avatars.githubusercontent.com/u/2580917?v=4)](https://github.com/joshuadegier "joshuadegier (10 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (9 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (7 commits)")[![axelitus](https://avatars.githubusercontent.com/u/732441?v=4)](https://github.com/axelitus "axelitus (6 commits)")[![belzaaron](https://avatars.githubusercontent.com/u/21190036?v=4)](https://github.com/belzaaron "belzaaron (6 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (5 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (4 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (4 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (4 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (4 commits)")[![mokhosh](https://avatars.githubusercontent.com/u/6499685?v=4)](https://github.com/mokhosh "mokhosh (4 commits)")[![josepdecid](https://avatars.githubusercontent.com/u/11754473?v=4)](https://github.com/josepdecid "josepdecid (4 commits)")[![SimonGenin](https://avatars.githubusercontent.com/u/5216993?v=4)](https://github.com/SimonGenin "SimonGenin (3 commits)")[![mkeremcansev](https://avatars.githubusercontent.com/u/76810832?v=4)](https://github.com/mkeremcansev "mkeremcansev (3 commits)")

---

Tags

eloquentlaravelmodelphpslugifyslugspatielaraveleloquenttranslatableslugslaravel-sluggableself-healing

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spatie-laravel-sluggable/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-sluggable/health.svg)](https://phpackages.com/packages/spatie-laravel-sluggable)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M633](/packages/spatie-laravel-medialibrary)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

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