New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

pharaonic/laravel-sluggable

Simple, multi-column slugs for Laravel Eloquent models, powered by Pharaonic PHP Slugify.
1,014 8
Install
composer require pharaonic/laravel-sluggable
Latest Version:13.1.0
PHP:>=8.3 <8.6
Laravel:13
Older releases:6 – 12
License:MIT
Last Updated:Oct 27, 2026
Links: GitHub  ·  Packagist
Maintainer: Pharaonic

PHP Version : 8.3 | 8.4 | 8.5 Laravel Version : 13.x License Build
Source Packagist Version Packagist Downloads

Simple, predictable slugs for Laravel Eloquent models.

Powered by PHP Slugify.

Installation

composer require pharaonic/laravel-sluggable

Usage

Laravel Sluggable can generate and maintain slugs automatically through Eloquent model events.

PHP Attributes

Configure your slug directly on the model using the Slug attribute:

use Illuminate\Database\Eloquent\Model;
use Pharaonic\Laravel\Sluggable\Attributes\Slug;
use Pharaonic\Laravel\Sluggable\Sluggable;

#[Slug(source: 'title')]
class Post extends Model
{
    use Sluggable;
}

The default target column is slug:

#[Slug(source: 'title', target: 'slug')]

Need more than one slug? Repeat the attribute:

#[Slug(source: 'title', target: 'slug', unique: true)]
#[Slug(source: 'seo_title', target: 'seo_slug')]
class Post extends Model
{
    use Sluggable;
}

Available attribute options include:

source, target, separator, unique, on_create, on_update, include_trashed, max_length, ascii_only, and ascii_lang.

Omitted options inherit the package defaults.

Use max_length: 0 when no length limit is required.

Callable Sources

PHP Attributes are designed for simple column-based sources.

For computed values, multiple columns, relations, or custom logic, use the existing sluggable() method:

public function sluggable(): array
{
    return [
        'slug' => [
            'source' => fn ($model) => $model->category->name.' '.$model->title,
        ],
    ];
}

Configuration Priority

Laravel Sluggable keeps all configuration styles backward compatible.

When more than one style is available, the package resolves them in this order:

sluggable() method
    ↓
PHP Attributes
    ↓
$sluggable property
    ↓
Package defaults

Definitions from different styles are not merged.

Package defaults only fill missing options for the selected configuration.

Existing $sluggable properties and sluggable() methods continue to work unchanged.

Documentation

For the complete API, configuration options, inheritance rules, validation behavior, and advanced usage, see the Laravel Sluggable Documentation.

Contributing

Contributions are welcome. See CONTRIBUTING.md.

Support & Security

See SUPPORT.md and SECURITY.md.

License

MIT. See LICENSE.

Related Packages

nunomaduro/laravel-sluggable

Automatic slug generation for Eloquent models via the #[Sluggable] attribute.

17,974 156
cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

15,799,101 3,997
bpocallaghan/sluggable

Provides a HasSlug trait that will generate a unique slug when saving your Larav...

27,800 6
neuecommerce/model-casts

Some handy Laravel Eloquent model casts.

24,914 0

Version History

Version Released PHP Laravel License
13.1.0 >=8.3 <8.6 ^13.0 MIT
13.0.0 >=8.3 <8.6 ^13.0 MIT
12.2.0 >=8.2 <8.6 ^12.0 MIT
12.1.0 >=8.2 <8.6 ^12.0 MIT
12.0.1 ~8.2|~8.3|~8.4 ^12.0 MIT