ausi/slug-generator
Generate clean, customizable slugs for URLs and filenames using PHP’s Transliterator (CLDR). Supports many scripts (Cyrillic, Greek, CJK), locale-aware conversions, configurable valid chars and delimiters, and consistent ASCII output via simple options.
Pros:
café → cafe or café).Cons:
Rule::unique).Str::slug() with SlugGenerator for consistent Unicode handling in Eloquent models./products/{slug}) with improved locale-aware normalization.post-1, post-2). Requires manual DB validation or integration with spatie/laravel-sluggable.| Risk Area | Mitigation Strategy |
|---|---|
| PHP 8.2+/9.0 Compatibility | Test with php -d intl.enable=true and validate against Laravel 10/11. Monitor for deprecation warnings. |
| Deprecated APIs | Check for warnings in symfony/polyfill-* dependencies; consider pinning versions. |
| Performance Bottlenecks | Benchmark against Str::slug() for high-volume use (e.g., 10K+ slugs/sec). Profile with Xdebug if latency is critical. |
| Locale-Specific Issues | Validate edge cases (e.g., Thai, Arabic scripts) with SlugGenerator::create('text', 'th'). Test CLDR updates for regressions. |
| Dependency Bloat | Audit composer why-not ausi/slug-generator to ensure no conflicts with existing packages. |
| Type Safety | Leverage PHPStan in CI to catch type-related issues early. |
php -v 8.2.0 and 8.3.0 to confirm compatibility. If issues arise, consider forking or patching.SlugGenerator::create('café', 'fr') vs. SlugGenerator::create('cafe', 'fr')).Rule::unique)?
spatie/laravel-sluggable or custom validation logic.spatie/laravel-sluggable for automatic slug generation/updates. The CLDR updates improve consistency for multilingual content.
use Spatie\Sluggable\HasSlug;
use Ausi\SlugGenerator\SlugGenerator;
class Post extends Model implements HasSlug {
public function getSlugOptions(): array {
return ['generator' => fn($title) => SlugGenerator::create($title)];
}
}
Route::get('{slug}', ...) with middleware to validate slugs (e.g., reject non-ASCII if needed).Str::slug() in prepareForValidation with SlugGenerator for consistent normalization.Str::slug(), custom functions).Str::slug() in a single model (e.g., Post) and test with multilingual content.café → cafe vs. café) and document changes.SlugGenerator.slug_v1 and slug_v2 column during transition if backward compatibility is critical.| Component | Compatibility Notes |
|---|---|
| PHP 8.0+ | Officially supported; test PHP 8.2+ for compatibility. |
| Laravel 9/10 | No known conflicts, but verify intl extension is loaded. |
| PHP 9.0 | Unconfirmed; test with php -v 9.0.0 if targeting future-proofing. |
| MySQL/PostgreSQL | Ensure slug columns use TEXT or VARCHAR(255) (Unicode support). |
| Existing Slugs | Run a migration to update old slugs if CLDR normalization rules differ (e.g., é → e). |
Post, Product, Category models to use SlugGenerator and validate CLDR changes.window.location.pathname).composer.json script to test theHow can I help you explore Laravel packages today?