laravel-sluggable (a well-established package). Minimal intrusion into core application logic.post-123) are less intuitive than localized alternatives (e.g., مقاله-اول).spatie/laravel-sluggable (≥2.0 for Laravel 8+). This is a low-risk dependency, widely adopted (10k+ stars) and actively maintained.slug column to target tables (if not pre-existing). Schema migrations are handled via spatie/laravel-sluggable, reducing customization overhead.generateSlugsFrom includes non-unique fields (e.g., duplicate titles). Mitigated by Spatie’s default collision handling (appends -2, -3, etc.).?dir=rtl or CSS unicode-bidi).saving). For high-write workloads, batch processing (e.g., Model::updateSlugs()) may be needed./en/{slug}) or client-side RTL detection?SlugOptions with doNotGenerateSlugsIfSlugIsEmpty() or unique().Route::get('/posts/{slug}', ...)).spatie/laravel-sluggable is installed (composer require spatie/laravel-sluggable).pishran/laravel-persian-slug:^2.0.pishran/laravel-persian-slug:1.4 (but be aware of maintenance risks).composer require pishran/laravel-persian-slug
php artisan vendor:publish --provider="Pishran\LaravelPersianSlug\LaravelPersianSlugServiceProvider"
slug column (if missing):
php artisan migrate
use HasPersianSlug;
use Spatie\Sluggable\SlugOptions;
class Post extends Model {
use HasPersianSlug;
public function getSlugOptions(): SlugOptions {
return SlugOptions::create()
->generateSlugsFrom('title')
->saveSlugsTo('slug')
->usingSeparator('-');
}
}
Route::get('/posts/{slug}', [PostController::class, 'show']);
Post::all()->each(function ($post) {
$post->save(); // Triggers slug generation
});
SlugOptions for advanced use cases (e.g., custom separators, field transformations):
->generateSlugsFrom(function () {
return strtolower($this->title . ' ' . $this->category->name);
})
spatie/laravel-sluggable is actively maintained (check for breaking changes).HasPersianSlug methods if default behavior (e.g., collision handling) is insufficient.Post::chunk(100, function ($posts) {
foreach ($posts as $post) {
$post->save(); // Batch slug generation
}
});
slug column for route resolution:
Schema::table('posts', function (Blueprint $table) {
$table->string('slug')->unique()->index();
});
| Scenario | Impact | Mitigation |
|---|---|---|
| Slug collision | Duplicate URLs or 404s | Use SlugOptions::unique() or custom logic. |
| RTL URL rendering issues | Broken frontend layouts | Test with RTL CSS frameworks (e.g., Tailwind). |
| Package incompatibility | Breaks slug generation | Fork or implement a fallback (e.g., manual slugging). |
| High write load | Slow slug generation | Batch processing or queue jobs. |
How can I help you explore Laravel packages today?