pharaonic/laravel-sluggable
| 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 |
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
Automatic slug generation for Eloquent models via the #[Sluggable] attribute.
Easy creation of slugs for your Eloquent models in Laravel
Provides a HasSlug trait that will generate a unique slug when saving your Larav...
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| | ^12.0 | MIT | |
| 12.0.0 | ~8.2| | ^12.0 | MIT | |
| 11.2.0 | >=8.2 <8.5 | ^11.0 | MIT | |
| 11.1.0 | >=8.2 <8.5 | ^11.0 | MIT | |
| 11.0.0 | ~8.2| | ^11.0 | MIT | |
| 10.1.0 | >=8.1 <8.4 | ^10.0 | MIT | |
| 10.0.0 | >=8.1 <8.4 | ^10.0 | MIT | |
| 9.1.0 | >=8.0 <8.3 | ^9.33 | MIT | |
| 9.0.0 | >=8.0 <8.3 | ^9.33 | MIT | |
| 8.1.0 | >=8.0 <8.2 | ^8.75 | MIT | |
| 8.0.0 | >=8.0 <8.2 | ^8.75 | MIT | |
| 7.1.0 | >=8.0 <8.1 | ^7.30 | MIT | |
| 7.0.0 | >=8.0 <8.1 | ^7.30 | MIT | |
| 6.1.0 | >=8.0 <8.1 | ^6.20 | MIT | |
| 6.0.0 | >=8.0 <8.1 | ^6.20 | MIT | |
| 1.0.4 | >=7.2 | >=6.0 | MIT | |
| 1.0.3 | >=7.2 | >=6.0 | MIT | |
| 1.0.2 | >=7.2 | >=6.0 | MIT | |
| 1.0.1 | >=7.2 | >=6.0 | MIT | |
| 1.0 | >=7.2 | >=6.0 | MIT |
