ariaieboy/laravel-persian-helpers

Add more functionality for Persian language into Laravel

1.0.0 2024-12-19 10:27 UTC

This package is auto-updated.

Last update: 2024-12-19 10:36:43 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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 and password_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.