Skip to content

v1.1.0

Choose a tag to compare

@Rayiumir Rayiumir released this 08 Jun 11:10
· 9 commits to main since this release
ff9f009

Changes :

What's New

1. Multi-language Support

  • Added support for fa (Persian), ar (Arabic), and en (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 SoftDeletes with optional withTrashed() 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