Releases: LaraPire/laravel-slugable
Releases · LaraPire/laravel-slugable
v1.1.2
v1.1.1
Laravel Slugable v2.0 - Modern Multi-Language Slug Generator
The new version of Laravel Slugable is here! v2.0 is a powerful and modern trait for generating SEO-friendly slugs in Laravel, with major improvements and full backward compatibility.
New Features & Improvements
Multi-Language Support
- Full support for Persian (fa), Arabic (ar), and English (en)
- Automatic conversion of Persian/Arabic digits to English
- Language-specific character cleaning and preservation
Enhanced Configuration
- Customizable separator (
-,_, etc.) - Configurable maximum slug length
- Force update option to regenerate slugs
- Unique slug enforcement with automatic counters
Static Slug Generation
- New
generateSlugFrom()method - Allows slug creation without a model instance (ideal for seeders, migrations, etc.)
Performance Optimizations
- Constant-based patterns for faster processing
- More efficient uniqueness checks
- Full support for soft-deleted models
Modern Codebase
- Uses PHP 8+ features (typed properties,
match, arrow functions) - Cleaner structure with focused methods
- Type-safe with strict comparisons
Installation
composer require rayiumir/laravel-slugableWhy Upgrade?
- Greater control over slug generation
- Improved performance
- Out-of-the-box multi-language support
- Clean, modern PHP 8+ codebase
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