denason / persian-slug
Generate SEO-friendly slugs for Persian text in Laravel applications
Requires
- php: >=8.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2025-05-13 07:58:41 UTC
README
A lightweight and SEO-friendly Persian slug generator for Laravel. Convert Persian, Arabic, and English strings into URL-friendly slugs with ease.
Features
- ✅ Converts Persian, Arabic, and English text to SEO-friendly slugs
- 🔢 Replaces Persian and Arabic numbers with English equivalents
- 🔀 Optional support for Laravel's
Str::slug()
- 🧪 Well-tested with PHPUnit
- 🧬 Includes
HasSlug
trait for automatic slug generation in Eloquent models
🎯 معرفی پکیج Persian Slug
Persian Slug یک پکیج سبک و کاربردی برای ساخت اسلاگهای سئو-پسند از متون فارسی و انگلیسی در پروژههای لاراول است.
🚀 امکانات کلیدی
- ✅ ساخت اسلاگ تمیز و خوانا از متون فارسی و انگلیسی
- ✅ تبدیل خودکار اعداد فارسی و عربی به معادل انگلیسی
- ✅ استفاده از Helper فانکشن
slug_fa()
برای سادگی بیشتر - ✅ افزودن Trait
HasSlug
به مدلها برای ذخیره خودکار و یکتای اسلاگ - ✅ قابلیت استفاده از Str::slug() داخلی لاراول
- ✅ کاملاً سازگار با Laravel 9 به بالا
- ✅ بدون نیاز به تنظیمات خاص
Installation
composer require denason/persian-slug
If you're using Laravel < 5.5, register the service provider manually in config/app.php
:
Denason\PersianSlug\PersianSlugServiceProvider::class,
Usage
1. Using the Helper Function
slug_fa('سلام دنیا ۱۲۳'); // Output: سلام-دنیا-123
2. Using the Static Method
use Denason\PersianSlug\SlugGenerator; SlugGenerator::make('سلام دنیا ۱۲۳'); // Output: سلام-دنیا-123
Optional Parameters:
SlugGenerator::make( string $text, string $separator = '-', bool $convertNumber = true, bool $useLaravelSlug = false ): string
3. Using HasSlug
Trait in Models
Automatically generate slugs when saving Eloquent models:
use Denason\PersianSlug\Concerns\HasSlug; class Post extends Model { use HasSlug; protected $slugSource = 'title'; // Field to slugify protected $slugField = 'slug'; // Field to store slug }
This will auto-generate a unique slug based on the title
attribute when saving the model.
Requirements
- PHP 8.0 or higher
- Laravel 9, 10, 11, or 12
License
MIT © Mohammad Asadi
Contributions
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
Credits
Crafted with ❤️ by Mohammad Asadi, Iran 🇮🇷
Links
- 📦 Packagist: denason/persian-slug
- 💻 GitHub: github.com/denason/persian-slug
- 🌐 Website: denason.ir