v1.1.0
Changes :
What's New
1. Multi-language Support
- Added support for
fa(Persian),ar(Arabic), anden(English). - Properly handles zero-width non-joiners, Tatweel, and script-specific characters.
- Custom regex patterns for each language for accurate slug cleanup.
2. Customization Options
- Set custom slug source and destination fields.
- Specify custom separator (default:
-). - Set maximum length for slugs.
- Force slug regeneration on every save.
- Enable/disable uniqueness check for slugs.
3. Improved Uniqueness Enforcement
- Ensures uniqueness using incremental suffixes (
-2,-3, etc.). - Skips current model record in uniqueness check.
- Supports models using
SoftDeleteswith optionalwithTrashed()check.
4. Better Code Structure
- Separated logic into clear, testable methods:
generateSlug()convertToSlug()convertNumbers()makeSlugUnique()slugExists()usesSoftDeletes()processLanguageSpecificChars()getCharacterPatternForLanguage()cleanUpSeparators()
- Uses type hinting and default values.
- More readable and maintainable.
5. Compatibility with Route Model Binding
getRouteKeyName()dynamically returns the slug field used for routing.
Example Usage
class Post extends Model
{
use HasSlugable;
// Optional configurations
protected $slugSourceField = 'title';
protected $slugDestinationField = 'slug';
protected $slugSeparator = '-';
protected $slugLanguage = 'fa'; // Supports 'fa', 'ar', 'en'
protected $slugMaxLength = 100;
protected $slugForceUpdate = false;
protected $slugShouldBeUnique = true;
}Thank you @itashia