pishran/persian-slug
pishran/persian-slug یک پکیج ساده برای ساخت اسلاگ استاندارد با پشتیبانی کامل از فارسی است. ورودیهای فارسی و انگلیسی را به اسلاگهای خوانا تبدیل میکند (مثل سلام دنیا → سلام-دنیا، Hello world → hello-world). نصب با Composer.
App\Services\SlugService) or used ad-hoc in controllers/models, adhering to SOLID principles.accessors/mutators) or form requests (e.g., slug field generation).VARCHAR fields.hello-سلام vs. hello-salam). Requires testing for non-standard inputs.spatie/laravel-sluggable) already in use?cocur/slug-generator (supports more locales) or custom logic if the package is abandoned.public function getSlugAttribute(): string
{
return str_slug_persian($this->title);
}
Illuminate\Validation\Rule:
'slug' => ['required', Rule::unique('posts')->ignore($post)],
slug columns:
php artisan make:migration add_slug_to_posts_table --table=posts
Post::chunk(100, function ($posts) {
foreach ($posts as $post) {
$post->update(['slug' => str_slug_persian($post->title)]);
}
});
str_slug for non-Persian content) if the package is deprecated.pishran\PersianSlug).dd(str_slug_persian($input)) to inspect outputs.slug columns for SEO and uniqueness checks:
Schema::table('posts', function (Blueprint $table) {
$table->string('slug')->unique();
});
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package abandonment | Broken slugs in production | Fork or replace with cocur/slug-generator |
| Character encoding issues | Corrupted slugs (e.g., "سلام" → "????") | Validate UTF-8 input, add fallback logic |
| Duplicate slugs | SEO conflicts, 404s | Use UUIDs or append IDs as suffixes |
| Performance degradation | Slow slug generation in bulk ops | Batch processing, caching |
tinker tests).slug_old) during migration.How can I help you explore Laravel packages today?