spatie/laravel-sluggable

Database and Eloquent

Generates a unique slug for an Eloquent model when it is created or updated.

The problem it solves

Slug generation needs uniqueness handling and a way to keep old URLs working when a title changes.

Install

composer require spatie/laravel-sluggable

Example

From the package README: the #[Sluggable] attribute, with optional self-healing URLs that combine slug and id.

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"

Requirements and activity

Fetched from Packagist and GitHub on 2026-11-29. Constraints show what the package allows, not what its maintainers tested.

Latest stable6.0.0 (2026-11-13)
PHP^8.4
Laravel^13.0
LicenseMIT
Downloads (Packagist, total)16,327,992
GitHub stars1,559
Last push2026-11-13
StatusNot marked abandoned

Strengths

  • Collisions get a -1, -2 suffix automatically.
  • Self-healing URLs redirect stale slugs with a 308 to the canonical URL (needs the HasSlug trait).

Limits to know

  • Closures, scoped uniqueness and conditional skipping need the HasSlug trait with getSlugOptions() instead of the attribute.

Official links

Documentation · Packagist · GitHub

Write-up based on: github.com/spatie/laravel-sluggable#readme. Written from the official README and docs; not tested by Laravel Questions. All packages.

Our network