PHPackages                             rayiumir/laravel-slugable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rayiumir/laravel-slugable

ActivePackage[Utility &amp; Helpers](/categories/utility)

rayiumir/laravel-slugable
=========================

Minimal auto slug trait for Laravel Eloquent models.

v1.1.2(6mo ago)88↓33.3%1MITPHPPHP ^8.0CI passing

Since Apr 5Pushed 6mo agoCompare

[ Source](https://github.com/LaraPire/laravel-slugable)[ Packagist](https://packagist.org/packages/rayiumir/laravel-slugable)[ RSS](/packages/rayiumir-laravel-slugable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (0)

Laravel Slugable
================

[](#laravel-slugable)

Laravel Slugable is a lightweight Laravel trait that automatically generates slugs from model fields like `title`, `name`, or any custom source — and stores it in a customizable destination field such as `slug`, etc.

Perfect for blogs, e-commerce, CMS, or any app that needs clean, readable, SEO-friendly URLs with multi-language support.

Features
--------

[](#features)

- Auto-generate slug on model creation
- Optional re-generation on model update
- Customizable source and destination fields
- Multi-language support (Persian, Arabic, English)
- Automatic conversion of non-English numbers
- Special character cleaning for each language
- Unique slug enforcement with counter
- Max length enforcement
- No external dependencies
- Static helper method for non-model usage
- Thread-safe implementation
- Type-safe operations

Installation
------------

[](#installation)

Install Package:

```
composer require rayiumir/laravel-slugable
```

After Publish Files:

```
php artisan vendor:publish --provider="Rayiumir\\Slugable\\ServiceProvider\\SlugableServiceProvider"
```

Basic Usage
-----------

[](#basic-usage)

Calling `HasSlugable` in Models `Post.php`:

```
class Post extends Model
{
    use HasSlugable;
}
```

Provided that the `title` and `slug` fields are in the database.

Advanced Configuration
----------------------

[](#advanced-configuration)

### Custom Field Names

[](#custom-field-names)

```
class Post extends Model
{
    use HasSlugable;

    protected $slugSourceField = 'name';       // Field to generate slug from
    protected $slugDestinationField = 'slug';  // Field to store slug in
    protected $slugUseForRoutes = false; // Use id for routes (default - no need to configure)
    protected $slugUseForRoutes = true; // Use slug for routes
}
```

### Language Support

[](#language-support)

```
class Post extends Model
{
    use HasSlugable;

    protected $slugLanguage = 'fa'; // Supports 'fa', 'ar', 'en'
}
```

### Other Options

[](#other-options)

```
class Post extends Model
{
    use HasSlugable;

    protected $slugSeparator = '_';      // Default: '-'
    protected $slugMaxLength = 100;      // Default: 250
    protected $slugForceUpdate = true;   // Force regenerate on update
    protected $slugShouldBeUnique = false; // Disable unique enforcement
}
```

Static Usage
------------

[](#static-usage)

You can generate slugs without a model instance:

```
$slug = Post::generateSlugFrom('My Post Title', [
    'language' => 'en',
    'separator' => '_',
    'maxLength' => 50
]);
```

Example Workflow
----------------

[](#example-workflow)

```
// Create with auto-slug
$post = new Post();
$post->title = 'Laravel ۱۲'; // Persian numbers
$post->save();

echo $post->slug; // Output: laravel-12

// Force update slug
$post->slugForceUpdate = true;
$post->title = 'New Laravel ۱۲';
$post->save();

echo $post->slug; // Output: new-laravel-12

// Generate slug without saving
$slug = Post::generateSlugFrom('Custom Title');
```

Language-Specific Handling
--------------------------

[](#language-specific-handling)

The trait automatically handles:

- Persian/Arabic numbers conversion
- ZWNJ (Zero-width non-joiner) removal for Persian
- Tatweel removal for Arabic/Persian
- Language-specific character preservation

Best Practices
--------------

[](#best-practices)

1. Add index to your slug column for better performance:

```
Schema::table('posts', function (Blueprint $table) {
    $table->string('slug')->unique()->index();
});
```

2. For large tables, consider adding the slug generation in a migration:

```
Post::chunk(200, function ($posts) {
    $posts->each->generateSlug();
});
```

3. Use the static method when generating slugs in migrations:

```
$posts->each(function ($post) {
    $post->slug = Post::generateSlugFrom($post->title);
    $post->save();
});
```

Performance Notes
-----------------

[](#performance-notes)

- The trait uses efficient string operations
- Language patterns are defined as constants for better performance
- Slug uniqueness check is optimized to exclude current model
- Works with soft-deleted models

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance67

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Recently: every ~51 days

Total

8

Last Release

194d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3917cc222ba14e6cbe11cb61f322d7b428fc3db06c8d285ebd2ada102156d13c?d=identicon)[Rayium](/maintainers/Rayium)

---

Top Contributors

[![Rayiumir](https://avatars.githubusercontent.com/u/11635923?v=4)](https://github.com/Rayiumir "Rayiumir (22 commits)")[![itashia](https://avatars.githubusercontent.com/u/203550694?v=4)](https://github.com/itashia "itashia (7 commits)")

---

Tags

laravellaravel-frameworklaravel-packagelaravel-sluggableslugslug-generatorslugablelaravellaravel-slugableeasy sluglaravel slugable packagelarapire

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rayiumir-laravel-slugable/health.svg)

```
[![Health](https://phpackages.com/badges/rayiumir-laravel-slugable/health.svg)](https://phpackages.com/packages/rayiumir-laravel-slugable)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[xefi/faker-php-laravel

Faker php integration with laravel

1915.1k](/packages/xefi-faker-php-laravel)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
