PHPackages                             wooserv/laravel-objectid - 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. wooserv/laravel-objectid

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

wooserv/laravel-objectid
========================

Elegant, fast ObjectId generator for Laravel models with automatic ID assignment, schema macro, and helper function.

v1.0.0(7mo ago)51423↓93.3%2[1 issues](https://github.com/wooserv/laravel-objectid/issues)MITPHPPHP &gt;=8.1CI passing

Since Nov 9Pushed 7mo agoCompare

[ Source](https://github.com/wooserv/laravel-objectid)[ Packagist](https://packagist.org/packages/wooserv/laravel-objectid)[ Docs](https://github.com/wooserv/laravel-objectid)[ RSS](/packages/wooserv-laravel-objectid/feed)WikiDiscussions main Synced today

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

⚡ Laravel ObjectId
==================

[](#-laravel-objectid)

Elegant, fast **ObjectId** generator for Laravel models — with automatic ID assignment, migration macro, and helper function.

[![Tests](https://github.com/wooserv/laravel-objectid/actions/workflows/tests.yml/badge.svg)](https://github.com/wooserv/laravel-objectid/actions/workflows/tests.yml)[![Packagist](https://camo.githubusercontent.com/804443df74e61f8d0dbd257efba340b73e0aab94eb67d42530721f8dbd6392c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776f6f736572762f6c61726176656c2d6f626a65637469642e737667)](https://packagist.org/packages/wooserv/laravel-objectid)[![License](https://camo.githubusercontent.com/726b37205aace0ff42ef84b7aba9fa622afd6b3874871ec611905a5cd9eb9ee4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f776f6f736572762f6c61726176656c2d6f626a65637469642e737667)](https://github.com/wooserv/laravel-objectid/blob/main/LICENSE)

> Laravel ObjectId brings the power and efficiency of MongoDB-style ObjectIds to your Eloquent models — with no database dependency.
>
> It’s a **drop-in, ultra-fast unique ID system** that fits seamlessly into Laravel’s model lifecycle.
>
> With this package, you can:
>
> - Automatically assign 24-character hex ObjectIds to your models.
> - Use `$table->objectId()` directly in your migrations.
> - Generate IDs anywhere using the global `objectid()` helper.
> - Enjoy compact, sortable, timestamp-encoded identifiers — **3× faster than UUIDs**.
>
> Built for performance, readability, and developer happiness.
>
> ---
>
> **Perfect for:**
>
> - Large-scale Laravel apps
> - Multi-database systems
> - UUID/ULID replacements
> - Caching and indexing optimization

---

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

[](#installation)

```
composer require wooserv/laravel-objectid
```

This package is auto-discovered by Laravel. No manual provider registration needed.

---

Usage
-----

[](#usage)

### 1. Model

[](#1-model)

```
use WooServ\LaravelObjectId\Concerns\HasObjectIds;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasObjectIds;
}
```

Now every new record gets a unique ObjectId automatically:

```
$post = Post::create(['name' => 'Hello World']);
echo $post->id; // e.g. 6730b6a0d8a28f890b7c9f40
```

---

### 2. Migration Macro

[](#2-migration-macro)

The service provider automatically adds a new macro to the schema builder:

```
Schema::create('posts', function (Blueprint $table) {
    $table->objectId(); // Creates string(24) primary key
    $table->string('name');
    $table->timestamps();
});
```

Optionally:

```
$table->objectId('uuid', false); // custom column, not primary
```

---

### 3. Helper Function

[](#3-helper-function)

```
$id = objectid(); // returns 24-char hex ObjectId string
```

---

Why Laravel ObjectId?
---------------------

[](#why-laravel-objectid)

FeatureObjectIdUUIDULIDSortable✅ Yes❌ No✅ YesLength24 chars36 chars26 charsContains Timestamp✅ Yes❌ No✅ YesIndex Friendly✅ Yes⚠️ Larger Indexes✅ YesCollision Chance🔒 Extremely Low🔒 Very Low🔒 Very Low---

Testing
-------

[](#testing)

```
composer test
```

Runs a full PHPUnit suite using an in-memory SQLite database.

---

⚡️ Benchmark Results
--------------------

[](#️-benchmark-results)

All benchmarks were executed on PHP 8.4 using in-memory SQLite and 10000 iterations per test on a local machine.

### ObjectId Generation Speed

[](#objectid-generation-speed)

```
Laravel ObjectId Benchmark (10000 iterations)
----------------------------------------------------------
ObjectId             : 0.412 µs per ID
objectid() helper    : 0.417 µs per ID
UUID                 : 1.283 µs per ID
ULID                 : 1.147 µs per ID
----------------------------------------------------------
Fastest: ObjectId

```

**Result:** `ObjectId` is roughly **3× faster** than UUID and **~2.7× faster** than ULID.

---

### Database Insert Performance

[](#database-insert-performance)

```
Database Insert Benchmark (1000 inserts)
----------------------------------------------------------
ObjectId   : 14.78 ms total (0.015 ms/insert)
UUID       : 15.48 ms total (0.015 ms/insert)
ULID       : 15.17 ms total (0.015 ms/insert)
----------------------------------------------------------

```

**Result:** Real-world insert performance is effectively identical across ID types, but **ObjectId maintains slightly lower overhead** during generation and indexing.

---

### Summary

[](#summary)

MetricObjectIdUUIDULIDGeneration Speed🥇 **Fastest**⚪ Slow⚪ MediumInsert Speed⚡ Very Fast⚡ Very Fast⚡ Very FastLength24 chars36 chars26 charsSortable✅ Yes❌ No✅ YesDB Index Size🔹 Small🔸 Large🔹 SmallHuman Readable⚪ Hex⚪ Hyphenated⚪ Base32Timestamp Embedded✅ Yes❌ No✅ Yes---

**Conclusion:**`Laravel ObjectId` provides *faster generation*, *compact indexes*, and *timestamp-friendly IDs* — ideal for large-scale Laravel applications.

---

License
-------

[](#license)

MIT © [WooServ](https://www.wooserv.com/)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance61

Regular maintenance activity

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

237d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24924319?v=4)[Hamada Habib](/maintainers/ihfbib)[@ihfbib](https://github.com/ihfbib)

---

Top Contributors

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

---

Tags

laravellaravel-frameworklaravel-packagemysqlobjectidphppostgresqluliduuidlaravelmigrationdatabaseeloquentlaravel-packageuuidulidmongodbunique-idid-generatorObjectIdmodel idwooServlaravel objectidlaravel macro

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wooserv-laravel-objectid/health.svg)

```
[![Health](https://phpackages.com/badges/wooserv-laravel-objectid/health.svg)](https://phpackages.com/packages/wooserv-laravel-objectid)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

267.8k](/packages/ntanduy-cloudflare-d1-database)[jenssegers/mongodb-lite

A lightweight MongoDB database library and model for Laravel 4

121.0k](/packages/jenssegers-mongodb-lite)

PHPackages © 2026

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