PHPackages                             devzero2in/laravel-uid-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. devzero2in/laravel-uid-generator

ActiveLibrary

devzero2in/laravel-uid-generator
================================

Laravel Unique ID Gegerator

074↓100%PHP

Since Feb 22Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Unique ID Generator
===========================

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

[![Latest Version on Packagist](https://camo.githubusercontent.com/4896d9c65943ea91d56f78af35b468c9fcb4dc7725e4f27468d2a8c6bed2895e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465767a65726f32696e2f6c61726176656c2d7569642d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devzero2in/laravel-uid-generator)[![Total Downloads](https://camo.githubusercontent.com/afa6b3af24e08e3e03f13e2dfe1b6dc97abb489ada3209de71a3aa02c0478fed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465767a65726f32696e2f6c61726176656c2d7569642d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devzero2in/laravel-uid-generator)[![License](https://camo.githubusercontent.com/58dc4c316f170cb5d37b8cb48868df6346d65fc0d97ef2ff36bab4f951c61068/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465767a65726f32696e2f6c61726176656c2d7569642d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A flexible and reliable package for generating unique IDs in Laravel. This package allows developers to generate custom IDs for any database table with options for setting prefixes, custom lengths, and field names.

---

📦 Features
----------

[](#-features)

- ✅ Generate unique IDs for any Eloquent model.
- ✅ Customize ID length and prefix.
- ✅ Prevent duplicate ID generation.
- ✅ Easy-to-use facade for quick integration.
- ✅ Configurable through Laravel's config system.

---

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require devzero2in/laravel-uid-generator
```

---

🔧 Configuration
---------------

[](#-configuration)

After installation, publish the configuration file (optional):

```
php artisan vendor:publish --tag=config
```

This will create a `config/uniqueid.php` file where you can set default values:

```
return [
    'default_length' => 8,   // Default ID length
    'default_prefix' => 'ID-', // Default ID prefix
];
```

---

⚙️ Usage
--------

[](#️-usage)

### **Basic Example**

[](#basic-example)

Generate a unique ID with default configuration:

```
use UniqueIdGenerator;

$id = UniqueIdGenerator::generate(App\Models\User::class);
```

### **Custom Length and Prefix**

[](#custom-length-and-prefix)

Generate a unique ID with custom length and prefix:

```
$id = UniqueIdGenerator::generate(App\Models\User::class, 'custom_id', 10, 'USR-');
```

### **Saving to a Model**

[](#saving-to-a-model)

Assign and save the generated ID to a model:

```
use App\Models\User;
use UniqueIdGenerator;

$user = new User();
$user->custom_id = UniqueIdGenerator::generate(User::class, 'custom_id', 12, 'USR-');
$user->name = 'Jane Doe';
$user->email = 'jane@example.com';
$user->save();
```

---

🏗️ Advanced Usage
-----------------

[](#️-advanced-usage)

Override the default field name for checking ID uniqueness:

```
$id = UniqueIdGenerator::generate(App\Models\Order::class, 'order_number', 6, 'ORD-');
```

---

🏛️ Service Provider &amp; Facade Registration
---------------------------------------------

[](#️-service-provider--facade-registration)

If auto-discovery is disabled, manually register the service provider and alias in `config/app.php`:

```
'providers' => [
    YourVendor\UniqueIdGenerator\UniqueIdGeneratorServiceProvider::class,
],

'aliases' => [
    'UniqueIdGenerator' => YourVendor\UniqueIdGenerator\Facades\UniqueIdGenerator::class,
],
```

---

✅ Testing
---------

[](#-testing)

Run package tests using PHPUnit:

```
vendor/bin/phpunit
```

---

📜 Changelog
-----------

[](#-changelog)

You can view the [changelog](CHANGELOG.md) for more information on recent changes.

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please follow these steps:

1. Fork the repository.
2. Create a new branch (`git checkout -b feature/YourFeature`).
3. Commit your changes (`git commit -m 'Add new feature'`).
4. Push to the branch (`git push origin feature/YourFeature`).
5. Create a new Pull Request.

---

🔒 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

📩 Support
---------

[](#-support)

// A cup of coffee would be appreciated.

[![Buy Me Coffee](https://camo.githubusercontent.com/ffae505f9c5991e7cc499179c1c430a95ba26e6eb46254df50ca5b11e2998a1a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532304d65253230436f666665652d2546302539462538442542352d677265656e2e737667)](https://www.buymeacoffee.com/devzero2in)

If you need any help or have questions, feel free to open an issue or contact me.

[![GitHub Issues](https://camo.githubusercontent.com/08922fa6fa9df7fbcca361595360936d35613ccce3da33fb0a68a0793d691340/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6465767a65726f32696e2f6c61726176656c2d7569642d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/devzero2in/laravel-uid-generator/issues)[![GitHub PRs](https://camo.githubusercontent.com/a0b3adb18f269aa4b2716c070c0ae53fa26a57e80d09a4dab2a4eb38b0a7dc81/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f70756c6c732f6465767a65726f32696e2f6c61726176656c2d7569642d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://github.com/devzero2in/laravel-uid-generator/pulls)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/74e8360c100674e546ab9f143ad0076e4dea4ebde1eb3010aed8d280e8054fc4?d=identicon)[devzero2in](/maintainers/devzero2in)

---

Top Contributors

[![devzero2in](https://avatars.githubusercontent.com/u/178060941?v=4)](https://github.com/devzero2in "devzero2in (5 commits)")

### Embed Badge

![Health badge](/badges/devzero2in-laravel-uid-generator/health.svg)

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

PHPackages © 2026

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