PHPackages                             myolbd/unique-slug - 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. [Database &amp; ORM](/categories/database)
4. /
5. myolbd/unique-slug

ActiveLibrary[Database &amp; ORM](/categories/database)

myolbd/unique-slug
==================

A Laravel package to generate unique and SEO-friendly slugs for modelsy

0.1.2(8mo ago)05MITPHPPHP &gt;=7.4

Since Aug 25Pushed 8mo agoCompare

[ Source](https://github.com/sujonmia019/unique-slug-laravel)[ Packagist](https://packagist.org/packages/myolbd/unique-slug)[ Docs](https://github.com/sujonmia019/unique-slug-laravel)[ RSS](/packages/myolbd-unique-slug/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Unique Slug Laravel
===================

[](#unique-slug-laravel)

A lightweight and flexible **Laravel package** to generate **unique, SEO-friendly slugs** for your Eloquent models.
Perfect for creating clean URLs for blogs, products, users, and more.

---

🚀 Features
----------

[](#-features)

- Generate **unique slugs** from any model field
- Prevents duplicates by auto-appending numbers
- Configurable separator and max retry count
- Works with any Eloquent model
- Supports Laravel &gt;=7x
- Includes Facade (`Slug::`) and Service Provider
- Publishable config file

---

📦 Installation
--------------

[](#-installation)

Require the package via Composer:

```
composer require myolbd/unique-slug
```

Configuration
-------------

[](#configuration)

**Service Provider Registration**In `config/app.php`, add in `providers` array -

```
'providers' => [
    // ...
    Myol\UniqueSlug\SlugServiceProvider::class,
    // ...
],
```

**Facade Class Alias**Add in aliases array -

```
'aliases' => Facade::defaultAliases()->merge([
    // ...
    'Slug' => Myol\UniqueSlug\Facades\Slug::class,
    // ...
])->toArray(),

## Use from Controller

#### Import first the UniqueSlug facade
```php
use Myol\UniqueSlug\Facades\Slug;
```

### Example #01- Post unique slug from title

[](#example-01--post-unique-slug-from-title)

Let's assume, we have in `Post` class, we've added `slug` column which is unique. Now, if we passed `title` and generate `slug` from that, then -

```
use App\Models\Post;

// First time create post with title Simple Post
Slug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post

// Second time create post with title Simple Post
Slug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post-1

// Third time create post with title Simple Post
Slug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post-2
```

### Example #02 - Pass custom separator

[](#example-02---pass-custom-separator)

Let's assume separator is `''` empty.

```
// First time create user.
Slug::generate(User::class, 'sujon', 'username', ''); // sujon

// Second time create user.
Slug::generate(User::class, 'sujon', 'username', ''); // sujon1

// Third time create user.
Slug::generate(User::class, 'sujon', 'username', ''); // sujon2
```

### Example - Unique slug for category or any model easily

[](#example---unique-slug-for-category-or-any-model-easily)

```
public function create(array $data): Category|null
{
    if (empty($data['slug'])) {
        $data['slug'] = Slug::generate(Category::class, $data['name'], 'slug');
    }

    return Category::create($data);
}
```

### Generate method -

[](#generate-method--)

```
Slug::generate($model, $value, $field, $separator);
```

```
/**
 * Generate a Unique Slug.
 *
 * @param object $model
 * @param string $value
 * @param string $field
 * @param string $separator
 *
 * @return string
 * @throws \Exception
 */
public function generate(
    $model,
    $value,
    $field,
    $separator = null
): string
```

#### Publish configuration

[](#publish-configuration)

```
php artisan vendor:publish myolbd/unique-slug
```

#### Configurations

[](#configurations)

```
return [
    /*
    |--------------------------------------------------------------------------
    | Slug default separator.
    |--------------------------------------------------------------------------
    |
    | If no separator is passed, then this default separator will be used as slug.
    |
    */
    'separator' => '-',

    /*
    |--------------------------------------------------------------------------
    | Slug max count limit
    |--------------------------------------------------------------------------
    |
    | Default 100, slug will generated like
    | test-1, test-2, test-3 .... test-100
    |
    */
    'max_count' => 100,
];
```

Contribution
------------

[](#contribution)

You're open to create any Pull request.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance59

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~3 days

Total

2

Last Release

262d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3dd97b4e4ee4ab470334b079b045088885ff3745d5894a42c2e5a84cea85b67b?d=identicon)[sujonmia019](/maintainers/sujonmia019)

---

Top Contributors

[![sujonmia019](https://avatars.githubusercontent.com/u/64095365?v=4)](https://github.com/sujonmia019 "sujonmia019 (3 commits)")

---

Tags

slugslugifylaraveleloquentseoslug-generatorUnique Slugurl-slugmodel-slug

### Embed Badge

![Health badge](/badges/myolbd-unique-slug/health.svg)

```
[![Health](https://phpackages.com/badges/myolbd-unique-slug/health.svg)](https://phpackages.com/packages/myolbd-unique-slug)
```

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[pishran/laravel-persian-slug

Creates Persian slugs for Eloquent models.

5527.6k1](/packages/pishran-laravel-persian-slug)[sirodiaz/laravel-redirection

Laravel package that allows storing in database (or other sources) urls to redirect for SEO purposes

6316.0k](/packages/sirodiaz-laravel-redirection)[matteoggl/linnaeus

A package to create readable, random slugs for Eloquent models from animal names and adjectives.

226.7k](/packages/matteoggl-linnaeus)

PHPackages © 2026

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