PHPackages                             monurakkaya/laravel-unique-code-generator - 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. monurakkaya/laravel-unique-code-generator

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

monurakkaya/laravel-unique-code-generator
=========================================

Provides unique code for your models

v1.0.2(3y ago)218.0k↓37.5%2MITPHPPHP ^7.4 || ^8.0

Since Jan 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/monurakkaya/laravel-unique-code-generator)[ Packagist](https://packagist.org/packages/monurakkaya/laravel-unique-code-generator)[ RSS](/packages/monurakkaya-laravel-unique-code-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

Laravel unique code generator
=============================

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

Provides unique code for your Eloquent models

INSTALLATION
------------

[](#installation)

```
composer require monurakkaya/laravel-unique-code-generator

```

USAGE
-----

[](#usage)

### The schema

[](#the-schema)

#### To create the column

[](#to-create-the-column)

```
// This will generate an unique string column named `code` 255 length which equivalent to $table->string('code', 255)->unique();
Schema::create('table', function (Blueprint $table) {
    ...
    $table->uniqueCode();
});

```

#### To drop the column

[](#to-drop-the-column)

```
Schema::table('table', function (Blueprint $table) {
    $table->dropUniqueCode();
});

```

#### To use your own column just pass the parameters to override the default values

[](#to-use-your-own-column-just-pass-the-parameters-to-override-the-default-values)

```
// on create
$table->uniqueCode('my_code', 'bigInteger', 32); // columnName, columnType, columnLength

// on drop
$table->dropUniqueCode('my_code');

```

Using schema helper is optional. You can go on with your own definitions.

### The model

[](#the-model)

Your model should use Monurakkaya\\Lucg\\HasUniqueCode trait to enable unique code functions:

```
use Monurakkaya\Lucg\HasUniqueCode;

class Foo extends Model {
    use HasUniqueCode;
}

```

and that's all.

```
$foo = Foo::create(['title' => 'Foo']);
#attributes: array:10 [▼
    "id" => 1
    "code" => "OF0EIL8B"
    "title" => "Foo"
    "created_at" => "2022-01-24 13:11:03"
    "updated_at" => "2022-01-24 13:11:03"
  ]

```

#### SETTINGS

[](#settings)

To change the column name just override the `uniqueCodeColumnName` method on your model

```

class Foo extends Model {
    use HasUniqueCode;

    protected static function uniqueCodeColumnName()
    {
        return 'my_code';
    }
}

```

\*\* Make sure your code column name to be equal to your column name. Default is `code`

To change the code type just override the `uniqueCodeType` method on your model

```

class Foo extends Model {
    use HasUniqueCode;

    protected static function uniqueCodeType()
    {
        return 'numeric';
    }
}

```

Available types are `'random_uppercase', 'random_lowercase', 'uuid', 'numeric'`. Default is `random_uppercase`

\*\* If you are going to use uuid, I recommend you to set column definition as uuid

To change the code length just override the `uniqueCodeLength` method on your model

```

class Foo extends Model {
    use HasUniqueCode;

    protected static function uniqueCodeLength()
    {
        return 32;
    }
}

```

\*\* Make sure your code length lte than column length. Default is `8`

Tests
-----

[](#tests)

To run the tests, execute the following from the command line, while in the project root directory:

```
./vendor/bin/phpunit
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~75 days

Total

3

Last Release

1425d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe63a20ff84ad0d46ff286893f0e77a1fc5c53961c6fcbe9df2748cf55a3aef6?d=identicon)[monurakkaya](/maintainers/monurakkaya)

---

Top Contributors

[![monurakkaya](https://avatars.githubusercontent.com/u/10274803?v=4)](https://github.com/monurakkaya "monurakkaya (11 commits)")

---

Tags

laravellaravelcode generatormodeleloquentlaravel unique code

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/monurakkaya-laravel-unique-code-generator/health.svg)

```
[![Health](https://phpackages.com/badges/monurakkaya-laravel-unique-code-generator/health.svg)](https://phpackages.com/packages/monurakkaya-laravel-unique-code-generator)
```

###  Alternatives

[shiftonelabs/laravel-cascade-deletes

Adds application level cascading deletes to Eloquent Models.

163632.1k2](/packages/shiftonelabs-laravel-cascade-deletes)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[adobrovolsky97/laravel-repository-service-pattern

Laravel 5|6|7|8|9|10 - Repository - Service Pattern

275.4k](/packages/adobrovolsky97-laravel-repository-service-pattern)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)

PHPackages © 2026

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