├── .gitignore ├── src ├── HasPersianString.php └── ServiceProvider.php ├── README.md ├── composer.json ├── LICENSE.md └── config └── persian-string.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /src/HasPersianString.php: -------------------------------------------------------------------------------- 1 | getPersianStrings() as $persianString) { 13 | if (is_string($model->{$persianString})) { 14 | $model->{$persianString} = $ps->convert($model->{$persianString}); 15 | } 16 | } 17 | }); 18 | } 19 | 20 | public function getPersianStrings() 21 | { 22 | return property_exists($this, 'persianStrings') ? $this->persianStrings : []; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Persian String 2 | 3 | تبدیل خودکار حروف، اعداد و کاراکترهای عربی، انگلیسی و ... به حروف، اعداد و کاراکترهای فارسی در مدل های لاراول 4 | 5 | 6 | ```php 7 | use Illuminate\Database\Eloquent\Model; 8 | use Pishran\LaravelPersianString\HasPersianString; 9 | 10 | class Post extends Model 11 | { 12 | use HasPersianString; 13 | 14 | protected $persianStrings = [ 15 | 'title', 16 | 'summary', 17 | 'content', 18 | ]; 19 | } 20 | ``` 21 | 22 | ## روش نصب 23 | 24 | برای نصب و استفاده از این پکیج می توانید از کمپوسر استفاده کنید: 25 | 26 | `composer require pishran/laravel-persian-string` 27 | 28 | ## پیکربندی 29 | 30 | انتشار فایل پیکربندی: 31 | 32 | `php artisan vendor:publish --provider="Pishran\LaravelPersianString\ServiceProvider"` 33 | 34 | جهت شخصی سازی قوانین تبدیل، فایل پیکربندی را ویرایش کنید: 35 | 36 | `config/persian-string.php` -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pishran/laravel-persian-string", 3 | "description": "Convert Arabic/English/etc numbers and characters to Persian numbers and characters in Laravel models.", 4 | "keywords": [ 5 | "laravel", 6 | "persian", 7 | "string" 8 | ], 9 | "homepage": "https://github.com/pishran/laravel-persian-string", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Farid Aghili", 14 | "email": "farid@pishranit.ir", 15 | "homepage": "https://www.faridaghili.ir", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "php": "^7.2|^8.0|^8.1|^8.2|^8.3|^8.4|^8.5", 21 | "illuminate/support": "^5.6|^5.7|^5.8|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", 22 | "pishran/persian-string": "^1.1" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "Pishran\\LaravelPersianString\\": "src" 27 | } 28 | }, 29 | "extra": { 30 | "laravel": { 31 | "providers": [ 32 | "Pishran\\LaravelPersianString\\ServiceProvider" 33 | ] 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 16 | __DIR__ . '/../config/persian-string.php' => config_path('persian-string.php'), 17 | ], 'config'); 18 | } 19 | 20 | /** 21 | * Register the application services. 22 | */ 23 | public function register() 24 | { 25 | $this->mergeConfigFrom( 26 | __DIR__ . '/../config/persian-string.php', 'persian-string' 27 | ); 28 | 29 | $this->app->singleton('PersianString', function () { 30 | $persianString = new PersianString(true); 31 | 32 | $persianString->addRules( 33 | config('persian-string.rules') 34 | ); 35 | 36 | return $persianString; 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Pishran Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /config/persian-string.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'أ' => 'ا', 16 | 'إ' => 'ا', 17 | 'ك' => 'ک', 18 | 'ؤ' => 'و', 19 | 'ة' => 'ه', 20 | 'ۀ' => 'ه', 21 | 'ي' => 'ی', 22 | '٠' => '۰', 23 | '0' => '۰', 24 | '١' => '۱', 25 | '1' => '۱', 26 | '٢' => '۲', 27 | '2' => '۲', 28 | '٣' => '۳', 29 | '3' => '۳', 30 | '٤' => '۴', 31 | '4' => '۴', 32 | '٥' => '۵', 33 | '5' => '۵', 34 | '٦' => '۶', 35 | '6' => '۶', 36 | '٧' => '۷', 37 | '7' => '۷', 38 | '٨' => '۸', 39 | '8' => '۸', 40 | '٩' => '۹', 41 | '9' => '۹', 42 | ';' => '؛', 43 | '?' => '؟', 44 | ',' => '،', 45 | ], 46 | 47 | ]; 48 | --------------------------------------------------------------------------------