- How do I install and use aferrandini/urlizer in Laravel?
- Run `composer require aferrandini/urlizer`, then register the service provider in `config/app.php`. Use the `Urlizer` facade or class directly: `Urlizer::urlize('Hello World!')` to generate `hello-world`. For Laravel 5–8, ensure the package is properly autoloaded via Composer.
- Does this package work with Laravel 9 or 10?
- No, this package is not officially supported for Laravel 9+. It was last updated in 2013 and may conflict with PHP 8.1+ features like strict typing or deprecated functions. Use alternatives like `spatie/sluggable` for modern Laravel versions.
- What’s the difference between this and Laravel’s built-in `Str::slug()`?
- `Str::slug()` is basic and lacks customization (e.g., handling accents or transliteration). This package offers predictable, configurable slugs with consistent normalization, making it ideal for SEO or legacy systems where `Str::slug()` falls short.
- Can I customize how special characters or accents are handled?
- Yes, the package allows basic configuration for transliteration and punctuation removal. However, it lacks advanced Unicode normalization (NFD/NFKC) or dynamic rule sets. For complex needs, consider alternatives like `cocur/slug-generator`.
- Will this break if I upgrade PHP to 8.1+?
- Potentially. The package targets PHP 5.3+ and may trigger deprecation warnings for functions like `strtolower` or `preg_replace`. Wrap usage in a compatibility layer or fork the package for modern PHP support.
- How does it handle slug collisions (e.g., duplicate URLs)?
- This package generates slugs deterministically but doesn’t include built-in collision detection. You’ll need to manually append counters (e.g., `-2`) or use Laravel’s `Str::slug()` fallback for uniqueness checks.
- Is there a way to cache slugs for performance?
- No, the package doesn’t include caching. For high-traffic apps, cache generated slugs in Redis or the filesystem using Laravel’s cache system, or batch-process slugs during off-peak hours.
- Does it support multilingual or non-Latin scripts (e.g., Arabic, Chinese)?
- No, this package focuses on basic Latin transliteration. For multilingual support, use alternatives like `spatie/sluggable` or `cocur/slug-generator`, which handle advanced Unicode normalization and transliteration rules.
- How do I integrate this with Eloquent models for automatic slugging?
- Manually add a `getSlugAttribute()` mutator to your model or use an accessor. Example: `public function getSlugAttribute() { return Urlizer::urlize($this->title); }`. For bulk operations, consider a model observer or service layer.
- Are there any alternatives if this package isn’t maintained?
- Yes. For Laravel, try `spatie/sluggable` (modern, feature-rich) or `cocur/slug-generator` (lightweight, Unicode-friendly). For non-Laravel PHP, `symfony/webpack-encore`’s slug utilities or custom regex-based solutions may suffice.