roundly-consulting / sluggable-for-laravel
Single- and multi-language (json/jsonb locale-map) slugs for Eloquent: multiple columns per model, scoped per-locale uniqueness with engine-native indexes, locale-aware route binding, SEO slug history — native, zero third-party deps.
Package info
github.com/roundly-consulting/sluggable-for-laravel
pkg:composer/roundly-consulting/sluggable-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- ext-json: *
- ext-mbstring: *
- illuminate/bus: ^12.0|^13.0
- illuminate/console: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/queue: ^12.0|^13.0
- illuminate/routing: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- illuminate/validation: ^12.0|^13.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
- ext-intl: Unicode NFKC normalisation of slug sources in unicode() mode (skipped when absent).
- roundly-consulting/translatable-for-laravel: Locale-map attributes; binds sluggable's SlugLocales to its SupportedLocales.
Provides
None
Conflicts
None
Replaces
None
README
Sluggable for Laravel
Single- and multi-language slugs for Eloquent: plain string slug columns and JSON locale-map
columns, scoped per-locale uniqueness backed by engine-native unique indexes, locale-aware route
model binding, validation rules and an optional slug history with 301 redirects. With the
defaults, ordinary input slugs exactly like Str::slug(), so adopting it keeps the slugs you
already have.
Installation
Requires PHP 8.4 and Laravel 12 or 13. The unique-index DDL needs PostgreSQL 12+, MySQL 8.0.23+ / MariaDB 10.3.3+ or SQLite 3.38+; generation and querying work on every Laravel driver.
composer require roundly-consulting/sluggable-for-laravel
Usage
Add the trait (zero config: slug is generated from name) and the column:
use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Sluggable\Concerns\HasSlug; use RoundlyConsulting\Sluggable\Contracts\Sluggable; final class Clinic extends Model implements Sluggable { use HasSlug; protected $fillable = ['name', 'slug']; } // in the migration $table->slug(); // string('slug', 255) $table->uniqueSlug(); // its unique index
Every save gets a unique slug, and it stays put when the name changes, so links never break:
use RoundlyConsulting\Sluggable\Facades\Slugs; Clinic::create(['name' => 'Happy Paws'])->slug; // "happy-paws" Clinic::create(['name' => 'Happy Paws'])->slug; // "happy-paws-2" Route::get('/clinics/{clinic:slug}', ShowClinic::class); Slugs::regenerate($clinic); // recompute from the new name and save Slugs::slugify('Žltý kôň @ home', language: 'sk'); // "zlty-kon-at-home"
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/sluggable-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md.