Powered by PHP Slugify.
composer require pharaonic/laravel-sluggableLaravel Sluggable can generate and maintain slugs automatically through Eloquent model events.
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.
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,
],
];
}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.
For the complete API, configuration options, inheritance rules, validation behavior, and advanced usage, see the Laravel Sluggable Documentation.
Contributions are welcome. See CONTRIBUTING.md.
See SUPPORT.md and SECURITY.md.
MIT. See LICENSE.
