![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
A tiny package to transforms arabic/eastern* to eastern*/arabic numbers for i.e ١٢٣٤٥٦٧٨ to 12345678 before validations to avoid invalid integers error when pass eastern numbers by (ios/mac) users, (*2)
- These numbers are known as أرقام هندية ("Indian numbers") in Arabic. They are sometimes also called "Indic numerals" in English. However, that is sometimes discouraged as it can lead to confusion with Indian numerals
Support version
| Laravel |
laravel-modules |
| 5.1 |
^1.0 |
| 5.8 |
^2.0 |
| 6.X |
^2.1 |
| 8.X |
^3.0 |
| 9.X |
^4.0 |
Install
Via Composer, (*3)
``` bash
$ composer require yemenifree/laravel-arabic-numbers-middleware, (*4)
## Usage
If you do not run Laravel 5.5 (or higher), then add the service provider in `config/app.php`:
```php
Yemenifree\LaravelArabicNumbersMiddleware\ServiceProvider::class,
If you do run the package on Laravel 5.5+, package auto-discovery takes care of the magic of adding the service provider., (*5)
That's it! by default package automatic transform all eastern numbers to arabic for all requests, (*6)
Package includes two middleware, (*7)
- "eastern-to-arabic" to transform numbers from eastern to arabic (i.e
١٢٣ to 123)
- "arabic-to-eastern" to transform numbers from arabic to eastern (i.e
123 to ١٢٣)
You can use middleware for custom router for example, (*8)
Route::any('/login', ['middleware' => 'eastern-to-arabic', function () {
// your code
}]);
you can ignore fields from transform by pass fields name as parameters to middleware for example, (*9)
// ignore transform pass field
Route::any('/login', ['middleware' => 'arabic-to-eastern:pass', function () {
// your code
}]);
// you can also ignore multi fields
Route::any('/login', ['middleware' => 'arabic-to-eastern:pass,test', function () {
// your code
}]);
inline ignore fields not work if auto_register_middleware enable and middleware you want to use inside auto_middleware option, instead you can set ignore fields in config file arabic-numbers-middleware.php, (*10)
Optional
if you want customizes configuration you can publish the configuration, (*11)
$ php artisan vendor:publish --provider="Yemenifree\LaravelArabicNumbersMiddleware\ServiceProvider"
This is the content of the published config file arabic-numbers-middleware.php:, (*12)
return [
/*
|--------------------------------------------------------------------------
| enable auto register middleware for all requests
|--------------------------------------------------------------------------
|
| if you want auto register for custom middleware group
| 'auto_register_middleware' => ['web'], //for web group only
| 'auto_register_middleware' => true, // all groups
| 'auto_register_middleware' => false, // none
*/
'auto_register_middleware' => true,
/*
|--------------------------------------------------------------------------
| list of middleware they will register for all requests automatic by package
|--------------------------------------------------------------------------
|
| Supported Middleware: "arabic-to-eastern", "eastern-to-arabic"
*/
'auto_middleware' => Yemenifree\LaravelArabicNumbersMiddleware\Middleware\TransformHindiToArabicNumbers::class,
/*
|--------------------------------------------------------------------------
| except transform fields ( POST | GET ) from all middleware
|--------------------------------------------------------------------------
|
| all none string value will be ignore by default, you can ignore fields by name (key) of POST or GET
|
*/
'except_from_all' => [
// 'login'
],
/*
|--------------------------------------------------------------------------
| except transform fields ( POST | GET ) from eastern to arabic
|--------------------------------------------------------------------------
|
| all none string value will be ignore by default, you can ignore fields by name (key) of POST or GET
|
*/
'except_from_eastern_to_arabic' => [
// 'mobile'
],
/*
|--------------------------------------------------------------------------
| except transform fields ( POST | GET ) from arabic to eastern
|--------------------------------------------------------------------------
|
| all none string value will be ignore by default, you can ignore fields by name (key) of POST or GET
|
*/
'except_from_arabic_to_eastern' => [
// 'mobile'
]
];
Change log
Please see CHANGELOG for more information on what has changed recently., (*13)
Testing
bash
$ composer test, (*14)
Contributing
Please see CONTRIBUTING for details., (*15)
Security
If you discover any security related issues, please email yemenifree@yandex.com instead of using the issue tracker., (*16)
Credits
License
The MIT License (MIT). Please see License File for more information., (*17)