pharaonic / laravel-sluggable
Simple, multi-column slugs for Laravel Eloquent models, powered by Pharaonic PHP Slugify.
Requires
- php: >=8.3 <8.6
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/support: ^13.0
- illuminate/view: ^13.0
- pharaonic/php-slugify: ~8.3.1 || ~8.4.0 || ~8.5.0
Requires (Dev)
- laravel/pint: ^1.21
- orchestra/testbench: ^11.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5.8 || ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-27 04:17:55 UTC
README
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.
