Model or dataset
cviebrock/eloquent-sluggable avatar
cviebrock/eloquent-sluggable

cviebrock/eloquent-sluggable: automatic URL slugs for Laravel Eloquent models

Easy creation of slugs for your Eloquent models in Laravel

3,997 stars448 forksPHPMIT

At a glance

What is it?
A trait-based package that turns a model attribute such as title into a unique, URL-friendly slug on save. It suits Laravel applications that want slugs generated in the model layer, and it expects you to add the slug column yourself.
Who is it for?
Adopt cviebrock/eloquent-sluggable if you want slug generation to live in the model, with uniqueness handled by the package and no service layer of your own. Skip it if you need slugs derived from translated content or generated outside Eloquent saves; the README does not describe translation support.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 31 days ago.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • cviebrock/eloquent-sluggable3,997 ★ · +0
Star history
Repository2026-09-242026-11-15
cviebrock/eloquent-sluggable4k4k

0 Stars in the last 52 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The problem: readable URLs without hand-written slug code

A blog post reachable at /post/1 is functional and forgettable. Using the title directly produces percent-encoded noise once the title contains an ampersand or an accented character. Laravel ships Str::slug(), which the README shows converting "My Dinner With André & François" into my-dinner-with-andre-francois, but calling that helper by hand in every controller leaves two jobs undone: deciding when the slug is regenerated, and keeping slugs unique when two posts share a title.

The package targets that gap. It is for Laravel developers who want the slug treated as a property of the model rather than a step in a controller or an observer they maintain themselves. The README frames the scope plainly: "Eloquent-Sluggable aims to handle all of this for you automatically, with minimal configuration." Minimal configuration here means one trait and one method on each model that needs a slug.

How the Sluggable trait hooks into Eloquent saves

You add the Sluggable trait to a model and implement an abstract sluggable() method that returns a configuration array. The array key is the destination field, so 'slug' => ['source' => 'title'] writes the generated value into the slug column from the title attribute. Because the destination is declared in PHP rather than in the database schema, the package does not create the column for you. The README is explicit that you add it "manually via your own migration" and that it should be NULLABLE.

The generation logic is not buried in the trait. The README documents a SlugService class as the component that builds slugs, and a dedicated section answers "When Is A Model Slugged?" rather than leaving the trigger implicit. Events are exposed too, so application code can react around slugging instead of guessing at the timing. Configuration is read from the model by default, and the README also documents a published configuration file for changing defaults globally. That split matters: per-model settings live next to the model, while separator, uniqueness and length limits can be set once.

Uniqueness is handled inside the package. The README shows the expected outcome when two posts share a title: my-dinner-with-andre-francois, then my-dinner-with-andre-francois-1, then -2. The config keys unique, uniqueSuffix and firstUniqueSuffix control that counter, and includeTrashed decides whether soft-deleted rows participate in the uniqueness check. That last key is the one people get wrong, because a trashed row holding a slug will block reuse unless you opt in.

Installing cviebrock/eloquent-sluggable and slugging a first model

Installation is one Composer command. The README notes that the package registers its service provider automatically, so there is no provider entry to add by hand:

bash
composer require cviebrock/eloquent-sluggable

If you want to change the defaults globally rather than per model, publish the configuration file. The README gives the provider class explicitly:

bash
php artisan vendor:publish --provider="Cviebrock\EloquentSluggable\ServiceProvider"

Next, add the slug column in your own migration. The README requires it to be nullable, and it tells you to add the column manually via your own migration.

Then attach the trait and declare the source attribute. This is the shape the README shows for a Post model:

php
use Cviebrock\EloquentSluggable\Sluggable;

class Post extends Model
{
    use Sluggable;

    /**
     * Return the sluggable configuration array for this model.
     *
     * @return array
     */
    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }
}

After that, saving a post with a title should populate the slug field. Create a second post with the same title and the counter suffix should appear, which is the quickest way to confirm uniqueness is active.

Where the package gets in the way

The nullable column requirement is a real constraint, not a formality. If you add the slug column as NOT NULL in an existing table with rows already present, the migration will fail or the existing rows will need backfilling before the package can write anything. The README does not document a backfill command, so populating slugs for a table that already has data is your problem to solve with a script or a migration of your own.

The version table is the other sharp edge. As of version 6.0 the package version is meant to match the Laravel version, so Laravel 11 takes ^11.0 and Laravel 12 takes ^12.0. Older Laravel releases map to 4.x package versions, and the README states those "are no longer supported or maintained." A project pinned to Laravel 5.8 that expects current fixes is out of luck. The README also warns that GitHub shows the master branch README by default, which may not match the version you installed, so the instructions you read may not describe the code you are running.

Lumen support has been dropped. If your application is built on Lumen rather than Laravel, this package is not the tool, and the README says so directly.

Spatie/laravel-sluggable and the difference in approach

Spatie/laravel-sluggable is the alternative that comes up most often, and the related searches around this package are full of Spatie names. The two solve the same problem from different directions. This package centres on a sluggable() method that returns a configuration array, and the README documents a SlugService class plus a set of scope helpers and route model binding support in separate files (SCOPE-HELPERS.md and ROUTE-MODEL-BINDING.md in the repository root).

The practical difference is where you express the rules. With cviebrock/eloquent-sluggable the model declares a source attribute and the package applies global defaults from the published config file. That suits teams that want one slugging policy across many models. If your slugs need to vary per locale, or you want the slug logic composed in a separate class rather than declared on the model, the Spatie package is the more natural fit. Neither is wrong; the choice is about whether slug configuration belongs on the model or beside it. The README for this package does not describe translation handling, so a multilingual site should check that requirement before choosing.

Maintenance, licence and upgrade cost

The repository is not archived, and the last push was on 2026-07-20, which puts it inside the six-month window. The project is under the MIT licence, which permits commercial use and modification provided the copyright notice and permission notice are retained; the LICENSE.md file sits at the repository root. That is a permissive arrangement, but it is not legal advice, so have your own counsel review it if the distinction matters to you.

Upgrade cost is tied to the version-matching rule. Because package versions track Laravel versions from 6.0 onward, a Laravel major upgrade usually means a package major upgrade in the same step. The repository carries CHANGELOG.md and UPGRADING.md for the specifics, and those are the files to read before bumping either dependency. There is also a TODO.md at the root, which suggests the maintainers keep an open list of unfinished work rather than treating the package as finished. The repository has no published GitHub releases, so the changelog is the place to look for what actually shipped.

Editorial conclusion

Adopt cviebrock/eloquent-sluggable if you want slug generation to live in the model, with uniqueness handled by the package and no service layer of your own. Skip it if you need slugs derived from translated content or generated outside Eloquent saves; the README does not describe translation support. Before committing, verify that your Laravel version matches the package version in the README table, confirm your own migration makes the slug column nullable, and check whether the default onUpdate behaviour fits a model whose title changes after publication.

Frequently asked questions

How do I create slugs in Laravel with cviebrock/eloquent-sluggable?

Install the package with Composer, add a nullable slug column in your own migration, then add the Sluggable trait to the model and return a configuration array from sluggable() that maps 'slug' to a source attribute such as 'title'. The package writes the slug when the model is saved.

Which package version of cviebrock/eloquent-sluggable matches my Laravel version?

As of version 6.0 the package version should match the Laravel version, so Laravel 12 uses ^12.0 and Laravel 11 uses ^11.0. Older Laravel releases map to 4.x package versions, which the README says are no longer supported or maintained.

Does cviebrock/eloquent-sluggable create the slug database column for me?

No. The README states that you need to add the column manually via your own migration, and that it should be NULLABLE.

What happens when two cviebrock/eloquent-sluggable models have the same title?

The package appends an incremental counter, producing my-dinner-with-andre-francois, then my-dinner-with-andre-francois-1, then -2. The unique, uniqueSuffix and firstUniqueSuffix config keys control this, and includeTrashed decides whether soft-deleted rows count toward uniqueness.

Is cviebrock/eloquent-sluggable still maintained?

The repository is not archived and the last push was on 2026-07-20. Note that Lumen support has been dropped, and package versions from 6.0 onward track the Laravel version.

Official sources

  1. cviebrock/eloquent-sluggable on GitHub
  2. Issues
  3. License: MIT
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/cviebrock-eloquent-sluggable.svg)](https://hysenlabs.com/projects/cviebrock-eloquent-sluggable)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/cviebrock-eloquent-sluggable.svg)](https://hysenlabs.com/projects/cviebrock-eloquent-sluggable)

Was this useful?