PHPackages                             sufian/slug-helper - 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. sufian/slug-helper

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

sufian/slug-helper
==================

A Laravel package for generating unique slugs.

v0.1.0(2y ago)04PHPPHP ^8.0

Since Sep 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Rubel-CSTE/packages)[ Packagist](https://packagist.org/packages/sufian/slug-helper)[ RSS](/packages/sufian-slug-helper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel-unique-slug-generator
=============================

[](#laravel-unique-slug-generator)

A simple but beautiful unique slug generator for Laravel eloquent model.

---

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

[](#installation)

```
composer require sufian/slug-helper
```

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

[](#configuration)

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

```
'providers' => [
    // ...
    Sufian\SlugHelper\SlugHelperServiceProvider::class,
    // ...
],
```

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

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

Use from Controller
-------------------

[](#use-from-controller)

#### Import first the UniqueSlug facade

[](#import-first-the-uniqueslug-facade)

```
use Sufian\SlugHelper\Facades\SlugHelperFacade;
```

### 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
UniqueSlug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post

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

// Third time create post with title Simple Post
UniqueSlug::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.
UniqueSlug::generate(User::class, 'sufian', 'username', ''); // sufian

// Second time create user.
UniqueSlug::generate(User::class, 'sufian', 'username', ''); // sufian_1

// Third time create user.
UniqueSlug::generate(User::class, 'sufian', 'username', ''); // sufian_2
```

### 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'] = UniqueSlug::generate(Category::class, $data['name'], 'slug');
    }

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

API Docs
--------

[](#api-docs)

### Generate method -

[](#generate-method--)

```
UniqueSlug::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 sufian/slug-helper
```

#### 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

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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

Unknown

Total

1

Last Release

959d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/31ad1a58fc0198031f9cddf0c00f947907274953c6439ef5a1ac4b1535c56b90?d=identicon)[Rubel-CSTE](/maintainers/Rubel-CSTE)

---

Top Contributors

[![sufianrubel](https://avatars.githubusercontent.com/u/80996172?v=4)](https://github.com/sufianrubel "sufianrubel (1 commits)")

### Embed Badge

![Health badge](/badges/sufian-slug-helper/health.svg)

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

###  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)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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