Weave Code
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
Slug Generator

Slug Generator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Slug Generator Library for PHP, based on Unicode’s CLDR data

Frequently asked questions about Slug Generator
How do I install ausi/slug-generator in a Laravel project?
Run `composer require ausi/slug-generator` to install the package. No additional Laravel-specific setup is required since it’s a standalone PHP library. For Eloquent integration, pair it with spatie/laravel-sluggable for automatic slug generation.
Does this package support Laravel 10 and PHP 8.2+?
The package hasn’t been updated since 2020, so compatibility with PHP 8.2+ and Laravel 10 isn’t guaranteed. Test thoroughly, especially with Intl extension dependencies, as symfony/polyfill-* may introduce warnings. Use `composer why-not ausi/slug-generator` to check for conflicts.
Can I use this for multilingual slugs (e.g., Arabic, Thai, or Cyrillic)?
Yes, the package leverages Unicode/CLDR support via IntlNormalizer, making it ideal for multilingual slugs. For example, `SlugGenerator::create('café', 'fr')` will handle accented characters consistently. Test edge cases like Thai or Arabic scripts to ensure proper normalization.
How do I handle slug collisions (e.g., duplicate URLs)?
The package itself doesn’t include duplicate-checking logic. You’ll need to manually validate slugs against your database or integrate with spatie/laravel-sluggable, which handles collisions automatically. For APIs, use Laravel’s `Rule::unique()` validation.
Can I customize the slug generation rules (e.g., allowed characters, separators)?
Yes, you can configure rules via the `SlugGenerator` constructor. For example, restrict separators to hyphens or allow only alphanumeric characters. This is useful for SEO or specific URL structures. Refer to the README for available options.
Is there a way to cache generated slugs to improve performance?
The package doesn’t include built-in caching, but you can wrap it in a decorator pattern to cache results in Redis or another store. This is useful for high-throughput applications like bulk content imports or APIs generating slugs repeatedly.
How do I integrate this with Eloquent models for automatic slug generation?
Combine it with spatie/laravel-sluggable by implementing the `HasSlug` trait and overriding `getSlugOptions()`. For example, return a closure that uses `SlugGenerator::create($title)` to generate slugs. This ensures slugs are updated automatically when titles change.
What happens if I pass invalid or unsupported locales (e.g., 'xx')?
The package will fall back to a default locale (likely English) if an unsupported locale is provided. Test with invalid locales like `'xx'` to confirm behavior. For production, validate input locales or use a default like `'en'` as a fallback.
Does this package work with Laravel’s service container (e.g., binding as a singleton)?
No, the package isn’t designed for Laravel’s service container. You’ll need to manually instantiate `SlugGenerator` or create a facade. For reusable instances, bind it in a service provider or use dependency injection in your application logic.
Are there alternatives to ausi/slug-generator for Laravel?
Yes, consider `spatie/laravel-sluggable` for Eloquent integration with built-in collision handling, or `cviebrock/eloquent-sluggable` for more advanced features like unique slugs. For standalone slug generation, `Str::slug()` is lightweight but lacks Unicode/CLDR support. Evaluate your needs for caching, async processing, or Laravel-specific features.
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.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php