spatie/laravel-sluggable

Generate slugs when saving Eloquent models
11,786,377 1,530
Install
composer require spatie/laravel-sluggable
Latest Version:3.8.1
PHP:^8.2
License:MIT
Last Updated:Apr 8, 2026
Links: GitHub  ·  Packagist
Maintainer: spatie

Generate slugs when saving Eloquent models

Latest Version on Packagist MIT Licensed GitHub Workflow Status Total Downloads

This package generates a unique slug for any Eloquent model whenever it is created or updated. Configure it with a #[Sluggable] attribute on the model, or with the HasSlug trait and a getSlugOptions() method when you need more control.

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"

Slugs are produced by Laravel's Str::slug helper. On top of generation, the package ships uniqueness resolution, translatable slugs (via spatie/laravel-translatable), self-healing URLs, and a set of overridable actions for the low-level work.

The package also bundles a Laravel Boost skill so AI assistants know how to use it. Boost discovers the skill automatically once both packages are installed. Read more in the Laravel Boost skill docs.

Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

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. We publish all received postcards on our virtual postcard wall.

Documentation

All documentation is available on our documentation site.

Installation

composer require spatie/laravel-sluggable

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.