├── .gitignore ├── LICENSE.md ├── README.md ├── composer.json └── src └── HasPersianSlug.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Persian Slug 2 | 3 | ایجاد اسلاگ استاندارد و فارسی در مدل های لاراول 4 | 5 | ```php 6 | use Illuminate\Database\Eloquent\Model; 7 | use Pishran\LaravelPersianSlug\HasPersianSlug; 8 | use Spatie\Sluggable\SlugOptions; 9 | 10 | class Post extends Model 11 | { 12 | use HasPersianSlug; 13 | 14 | public function getSlugOptions(): SlugOptions 15 | { 16 | return SlugOptions::create() 17 | ->generateSlugsFrom('title') 18 | ->saveSlugsTo('slug'); 19 | } 20 | } 21 | ``` 22 | 23 | اطلاعات بیشتر در مورد کلاس SlugOptions: 24 | 25 | https://github.com/spatie/laravel-sluggable#usage 26 | 27 | ## روش نصب 28 | 29 | برای نصب و استفاده از این پکیج می توانید از کامپوزر استفاده کنید: 30 | 31 | `composer require pishran/laravel-persian-slug` 32 | 33 | ## نسخه های قدیمی تر 34 | برای لاوارل ۸ به بعد از آخرین نسخه این پکیج و برای لاراول ۷ از نسخه ۱.۴ استفاده کنید. 35 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pishran/laravel-persian-slug", 3 | "description": "Creates Persian slugs for Eloquent models.", 4 | "keywords": [ 5 | "laravel", 6 | "persian", 7 | "slug", 8 | "eloquent" 9 | ], 10 | "homepage": "https://github.com/pishran/laravel-persian-slug", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Farid Aghili", 15 | "email": "farid@pishranit.ir", 16 | "homepage": "https://www.faridaghili.ir", 17 | "role": "Developer" 18 | } 19 | ], 20 | "require": { 21 | "php": "^7.3|^8.0", 22 | "spatie/laravel-sluggable": "^2.0|^3.0", 23 | "pishran/persian-slug": "^1.0" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Pishran\\LaravelPersianSlug\\": "src" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/HasPersianSlug.php: -------------------------------------------------------------------------------- 1 | generateSlugsFrom('name') 19 | ->saveSlugsTo('slug'); 20 | } 21 | 22 | /** 23 | * Generate a non unique slug for this record. 24 | */ 25 | protected function generateNonUniqueSlug(): string 26 | { 27 | if ($this->hasCustomSlugBeenUsed()) { 28 | $slugField = $this->slugOptions->slugField; 29 | 30 | return $this->$slugField; 31 | } 32 | 33 | return str_slug_persian($this->getSlugSourceString(), $this->slugOptions->slugSeparator); 34 | } 35 | 36 | /** 37 | * Get the value of the model's route key. 38 | * 39 | * @return mixed 40 | */ 41 | public function getRouteKeyName() 42 | { 43 | $this->slugOptions = $this->getSlugOptions(); 44 | 45 | return $this->slugOptions->slugField; 46 | } 47 | } 48 | --------------------------------------------------------------------------------