Pros:
#[Sluggable] attribute aligns with modern PHP 8+ attribute-based syntax, improving readability and maintainability.title or name fields) while allowing customization via configuration or attributes. Reduces boilerplate for common use cases.unique:slug) and optional caching (e.g., Sluggable::generate()) to minimize redundant slug generation.Cons:
toSlug() methods or middleware.nunomaduro/laravel-sluggable) and minimal configuration (publish migrations if using database-backed slugs).#[Sluggable]) and traditional method-based (sluggable()) configurations, easing migration for existing projects.Sluggable::generate() with custom uniqueness handlers or application-level locks.301 mappings) or gradual rollout.Route::redirect()) feasible for legacy slugs?unique constraints for slugs).Route::model() or implicit binding).composer.json for exact versions). For Laravel 11+, verify compatibility with PHP 8.3+.BlogPost).#[Sluggable]) and method-based configurations.#[Sluggable].slug columns if not already present:
php artisan vendor:publish --provider="NunoMaduro\LaravelSluggable\SluggableServiceProvider" --tag="migrations"
php artisan migrate
use NunoMaduro\LaravelSluggable\Sluggable;
Model::query()->each(function ($model) {
$model->slug = Sluggable::generate($model);
$model->save();
});
getSlugAttribute() or boot() methods with #[Sluggable] or sluggable().Route::get('/posts/{post:slug}', ...)).slug column.spatie/laravel-sluggable). Avoid mixing packages.spatie/laravel-honeypot or laravel-nestedset if used.composer require nunomaduro/laravel-sluggable
dd()) aid troubleshooting.Sluggable::generate() with Redis).Schema::table('posts', function (Blueprint $table) {
$table->string('slug')->unique()->index();
});
How can I help you explore Laravel packages today?