PHPackages                             verbanent/eloquent-binary-uuid - 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. verbanent/eloquent-binary-uuid

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

verbanent/eloquent-binary-uuid
==============================

Ordered binary UUID in Laravel / Eloquent based on UUID version 1

v1.10.0(5mo ago)311.3k↓43.3%3[1 issues](https://github.com/verbanent/eloquent-binary-uuid/issues)MITPHPPHP ^7.3|^8CI failing

Since Mar 16Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/verbanent/eloquent-binary-uuid)[ Packagist](https://packagist.org/packages/verbanent/eloquent-binary-uuid)[ Docs](https://github.com/verbanent/eloquent-binary-uuid)[ RSS](/packages/verbanent-eloquent-binary-uuid/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (24)Used By (0)

Ordered binary UUID in Laravel / Eloquent
=========================================

[](#ordered-binary-uuid-in-laravel--eloquent)

[![Quality Gate Status](https://camo.githubusercontent.com/fc84e9da6332b1f180126b28ed92e999929f2b41e1b8b5432e594a693044a799/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d76657262616e656e745f656c6f7175656e742d62696e6172792d75756964266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=verbanent_eloquent-binary-uuid)[![Downloads](https://camo.githubusercontent.com/51df336843984ea335515f564d844c4a0ecf22e277a65a103a0fe0ffde188a7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76657262616e656e742f656c6f7175656e742d62696e6172792d757569642e737667)](https://packagist.org/packages/verbanent/eloquent-binary-uuid)[![StyleCI](https://camo.githubusercontent.com/9d19d6977e16f2e519f7003d580b7f2a106b5a5cc3be32bcf9d706ac2d195c67/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3238353832363434392f736869656c643f6272616e63683d6d61696e)](https://github.styleci.io/repos/285826449?branch=main)[![CodeFactor](https://camo.githubusercontent.com/34e84dc5078d7e512764663a07dc9cd08f75c4a4ee46b48e679cdf9de7ffacb8/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f76657262616e656e742f656c6f7175656e742d62696e6172792d757569642f62616467652f6d61696e)](https://www.codefactor.io/repository/github/verbanent/eloquent-binary-uuid/overview/main)[![Maintainability Rating](https://camo.githubusercontent.com/27014a779ff139c3e495f83c16220f6ce7226a698fb0f18bdfdc957e6b5f1558/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d76657262616e656e745f656c6f7175656e742d62696e6172792d75756964266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/dashboard?id=verbanent_eloquent-binary-uuid)[![Lines of Code](https://camo.githubusercontent.com/b7ae462f3b624ce85d2a797567f72198183cabcbc6832f376006f71ae364d13e/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d76657262616e656e745f656c6f7175656e742d62696e6172792d75756964266d65747269633d6e636c6f63)](https://sonarcloud.io/dashboard?id=verbanent_eloquent-binary-uuid)[![Coverage](https://camo.githubusercontent.com/7b38d6b816ee1fe12dee8dfd68e35fa3f62e9caa00f936c3f5d7b4e1ed397cd2/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d76657262616e656e745f656c6f7175656e742d62696e6172792d75756964266d65747269633d636f766572616765)](https://sonarcloud.io/dashboard?id=verbanent_eloquent-binary-uuid)[![Packagist Version](https://camo.githubusercontent.com/bbb684898c6ecf88c29466d8aba273a67f221688789b5450e1f4f4c3d1b694f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76657262616e656e742f656c6f7175656e742d62696e6172792d75756964)](https://camo.githubusercontent.com/bbb684898c6ecf88c29466d8aba273a67f221688789b5450e1f4f4c3d1b694f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76657262616e656e742f656c6f7175656e742d62696e6172792d75756964)[![Packagist PHP Version Support](https://camo.githubusercontent.com/225e5f27a16d48fb76f8d0bfc944e0cc554af23f7595623cd55c7e14e32c1b51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76657262616e656e742f656c6f7175656e742d62696e6172792d75756964)](https://camo.githubusercontent.com/225e5f27a16d48fb76f8d0bfc944e0cc554af23f7595623cd55c7e14e32c1b51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76657262616e656e742f656c6f7175656e742d62696e6172792d75756964)[![Packagist License](https://camo.githubusercontent.com/e8d82ed45c91376f3723ea60c57bb0d814f79f4e5da9d302217d41728feba3d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76657262616e656e742f656c6f7175656e742d62696e6172792d75756964)](https://camo.githubusercontent.com/e8d82ed45c91376f3723ea60c57bb0d814f79f4e5da9d302217d41728feba3d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76657262616e656e742f656c6f7175656e742d62696e6172792d75756964)

Based on articles about the optimization of UUID storage in databases, I decided to write a simple library that allows this in my projects. I based on the information available here:

[https://percona.community/blog/2018/10/12/generating-identifiers-auto\_increment-sequence/](https://percona.community/blog/2018/10/12/generating-identifiers-auto_increment-sequence/)

The package currently only supports MySQL.

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

[](#installation)

Please install the package via Composer:

```
composer require verbanent/eloquent-binary-uuid
```

Basic example
-------------

[](#basic-example)

This example keeps things simple: `Foo` and `Bar` both use UUID primary keys, and `Bar.foo_id` references `Foo.id`.

### Migrations

[](#migrations)

```
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

Schema::create('foos', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->string('name')->nullable();
    $table->timestamps();
});

Schema::create('bars', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->uuid('foo_id');
    $table->string('title')->nullable();
    $table->timestamps();

    $table->foreign('foo_id')->references('id')->on('foos')->cascadeOnDelete();
});
```

### Models

[](#models)

```
namespace App\Models;

use Verbanent\Uuid\AbstractModel;

class Foo extends AbstractModel
{
    protected $fillable = ['name'];

    public function bars()
    {
        return $this->hasMany(Bar::class, 'foo_id');
    }
}
```

```
namespace App\Models;

use Verbanent\Uuid\AbstractModel;
use Verbanent\Uuid\Traits\ForeignBinaryUuidSupportableTrait;

class Bar extends AbstractModel
{
    protected $fillable = ['title'];

    public function foo()
    {
        return $this->belongsTo(Foo::class, 'foo_id');
    }
}
```

### Usage

[](#usage)

```
$foo = \App\Models\Foo::create(['name' => 'Alpha']);

$bar = new \App\Models\Bar(['title' => 'Child']);
$bar->foo()->associate($foo);
$bar->save();
```

Examples
--------

[](#examples)

More scenarios are documented in the `examples/` directory:

- `examples/01-single-model-uuid-primary-key.md`
- `examples/02-two-models-uuid-pk-and-fk.md`
- `examples/03-creating-entities-with-binary-uuid.md`
- `examples/04-creating-entities-with-string-uuid.md`
- `examples/05-querying.md`

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

[](#configuration)

If you want a global default UUID column name, publish the config and set the environment variable.

1. Publish the config file:

```
php artisan vendor:publish --provider="Verbanent\\Uuid\\Providers\\BinaryUuidServiceProvider" --tag=binary-uuid-config
```

2. Set the default column name in `.env`:

```
BINARY_UUID_DEFAULT_COLUMN=uuid

```

3. Refresh config:

```
php artisan config:clear
# or
php artisan config:cache
```

Per-model override still works and takes precedence:

```
protected $uuidColumn = 'custom_uuid';
```

Unit tests
----------

[](#unit-tests)

Run this command if you want to check unit tests:

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

Or if you want to check code coverage:

```
phpdbg -qrr vendor/bin/phpunit --coverage-html coverage tests
```

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance63

Regular maintenance activity

Popularity28

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 96.3% 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 ~113 days

Recently: every ~367 days

Total

23

Last Release

172d ago

PHP version history (3 changes)v1.2.4PHP ^7.3

v1.6.0PHP ^7.3|^8.0

v1.8.0PHP ^7.3|^8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44390595?v=4)[Radek Ziemniewicz](/maintainers/radek-ziemniewicz)[@radek-ziemniewicz](https://github.com/radek-ziemniewicz)

---

Top Contributors

[![radek-ziemniewicz](https://avatars.githubusercontent.com/u/44390595?v=4)](https://github.com/radek-ziemniewicz "radek-ziemniewicz (78 commits)")[![egarcia-add](https://avatars.githubusercontent.com/u/63585401?v=4)](https://github.com/egarcia-add "egarcia-add (2 commits)")[![krowinski](https://avatars.githubusercontent.com/u/1478555?v=4)](https://github.com/krowinski "krowinski (1 commits)")

---

Tags

binaryeloquentforeignhexindexkeylaravelorderedprimaryuuidlaraveleloquentuuidhexbinaryordered

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/verbanent-eloquent-binary-uuid/health.svg)

```
[![Health](https://phpackages.com/badges/verbanent-eloquent-binary-uuid/health.svg)](https://phpackages.com/packages/verbanent-eloquent-binary-uuid)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4843.1M9](/packages/dyrynda-laravel-model-uuid)[weebly/laravel-mutate

Mutate Laravel attributes

1356.1k](/packages/weebly-laravel-mutate)[jrsaunders/shard-matrix

A Complete Database Sharding system for MYSQL and/or Postgres. Using Laravels Query Builder easily scale up your application. Configure your whole solution in one Yaml Config file.

271.5k](/packages/jrsaunders-shard-matrix)

PHPackages © 2026

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