ariaieboy / laravel-persian-helpers
Add more functionality for Persian language into Laravel
Fund package maintenance!
Ariaieboy
Requires
- php: ~8.4
- illuminate/contracts: ^v11.35.1
- spatie/laravel-package-tools: ^1.17.0
Requires (Dev)
- barryvdh/laravel-ide-helper: ^3.3
- larastan/larastan: ^3.0.2
- laravel/pint: ^1.18.3
- nunomaduro/collision: ^8.5.0
- orchestra/testbench: ^9.8.0
- pestphp/pest: ^3.7.1
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan-deprecation-rules: ^2.0.1
- phpstan/phpstan-phpunit: ^2.0.3
README
This package will add some helpers and macros to the laravel that help you work with persian language and convert non persian character and digits to persian or vise-versa.
Requirement
This package requires php version >= 8.4
and laravel version >= 11.35.1
Installation
You can install the package via composer:
composer require ariaieboy/laravel-persian-helpers
You can publish the config file with:
php artisan vendor:publish --tag="laravel-persian-helpers-config"
Usage
Facade
PersianHelpers::toEnglishDigit('۱۲۳۴'); // will return "1234" PersianHelpers::toPersianDigit('1234٥٤'); // will return "۱۲۳۴۵۴" PersianHelpers::toPersianLetter(',;كإأؤةۀي?'); // will return "،؛کااوههی؟" PersianHelpers::toPersian('12ي'); // will return "۱۲ی"
Str
macros
Str::toEnglishDigit('۱۲۳۴'); // will return "1234" Str::toPersianDigit('1234٥٤'); // will return "۱۲۳۴۵۴" Str::toPersianLetter(',;كإأؤةۀي?'); // will return "،؛کااوههی؟" Str::toPersian('12ي'); // will return "۱۲ی"
Middlewares
By using these middlewares all the user inputs will be converted to correct format.
use Ariaieboy\LaravelPersianHelpers\Http\Middleware\ToEnglishDigit; use Ariaieboy\LaravelPersianHelpers\Http\Middleware\ToPersianDigit; use Ariaieboy\LaravelPersianHelpers\Http\Middleware\ToPersianLetter; use Ariaieboy\LaravelPersianHelpers\Http\Middleware\ToPersian; Route::post('example1')->middleware(ToEnglishDigit::class); Route::post('example2')->middleware(ToPersianDigit::class); Route::post('example3')->middleware(ToPersianLetter::class); Route::post('example4')->middleware(ToPersian::class);
Note: by default
current_password
,password
andpassword_confirmation
inputs are ignored and are not affected by this middleware to customize this behavior you should extend each of this middleware and change the$except
property of the middleware
class MyCustomToEnglishDigitMiddleware extends \Ariaieboy\LaravelPersianHelpers\Http\Middleware\ToEnglishDigit{ /** * @var array<string> */ protected array $except = [ 'title', 'password' ]; } Route::post('example')->middleware(MyCustomToEnglishDigitMiddleware::class);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.