Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Sluggable

Laravel Sluggable Laravel Package

padosoft/laravel-sluggable

A Laravel package for automatically generating and maintaining slugs for Eloquent models. It simplifies creating SEO-friendly, unique URLs from model attributes, with configurable slug sources and handling for duplicate or updated values.

View on GitHub
Deep Wiki
Context7

Package to create slugs for Eloquent models (Modified version of spatie package)

Frequently asked questions about Laravel Sluggable
How do I install padosoft/laravel-sluggable in a Laravel app?
Install it with Composer by running composer require padosoft/laravel-sluggable. Laravel's package auto-discovery registers the service provider, so manual wiring is usually unnecessary. If the package ships a config file, publish it with php artisan vendor:publish and adjust the defaults to match your models.
How do I add a slug to an Eloquent model?
Add the package's slug trait to the model and implement the slug options method it expects. Inside that method you return a slug options object describing which attribute or attributes the slug should be built from. Once the trait is in place, slugs are generated automatically when the model is created.
How is this package different from spatie/laravel-sluggable?
It is a modified version of the Spatie package, so the core trait-and-options API will feel familiar. The Padosoft fork may add its own tweaks, defaults, or fixes, so check the repository README and changelog for the exact differences. If you already use Spatie's package, switching is usually a matter of swapping the Composer dependency and namespace.
Can I generate a slug from a column other than title?
Yes, the slug source is configurable through the slug options, so you can point it at name, headline, or any other attribute. You can also combine multiple attributes to build a single slug. Make sure the source field is populated before the model is saved, otherwise the generated slug will be empty or partial.
How does the package handle duplicate slugs?
When a generated slug already exists, the package appends a numeric suffix to keep the value unique. In production you should also add a unique index on the slug column so concurrent writes cannot slip a duplicate through. For high write concurrency, catch duplicate-key exceptions and retry generation.
Can I prevent the slug from changing when a model is updated?
Yes, the slug options include a setting that disables slug regeneration on updates. This matters for SEO, because changing a live URL breaks inbound links and bookmarks. A common approach is to generate the slug once on create and only regenerate it deliberately, with a redirect in place.
Which Laravel versions does padosoft/laravel-sluggable support?
Support depends on the version constraints declared in the package's composer.json. Check the require block and any compatibility notes in the README for the Laravel and PHP versions you plan to use. If you are on a very new Laravel release, verify compatibility before upgrading a production application.
Can I customise how the slug string is built?
Slugs are typically produced with Laravel's Str::slug helper, so separators, casing, and transliteration follow that behaviour. Most forks also let you supply a custom slug-generation callback when you need full control. That is useful for non-Latin alphabets or domain-specific formatting rules.
How do I backfill slugs for existing records?
Loop over the existing rows and re-save them, or call the slug generation method directly on each model. Do the work in chunks or a queued job so large tables do not time out. Add the unique index after the backfill completes to avoid failures on partially populated data.
How should I test slugs in my application's test suite?
Use an in-memory SQLite database or a dedicated test database that includes the slug column, then create models and assert the expected slug values. Also write tests for duplicate titles resolving to suffixed slugs and for updates leaving the slug untouched. RefreshDatabase keeps each test isolated and prevents unique-index conflicts between tests.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager