PHPackages                             linshunwei/laravel-ulid - 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. linshunwei/laravel-ulid

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

linshunwei/laravel-ulid
=======================

Laravel package for ULID (Universally Unique Lexicographically Sortable Identifier)

3.0.1(3mo ago)010MITPHPPHP ^7.0|^8.0|^8.1|^8.2|^8.3|^8.4

Since Feb 5Pushed 3mo agoCompare

[ Source](https://github.com/linshunwei/laravel-ulid)[ Packagist](https://packagist.org/packages/linshunwei/laravel-ulid)[ Docs](https://github.com/linshunwei/laravel-ulid)[ RSS](/packages/linshunwei-laravel-ulid/feed)WikiDiscussions master Synced 1mo ago

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

来自

Laravel ULID
============

[](#laravel-ulid)

Laravel package to generate ULID (Universally Unique Lexicographically Sortable Identifier), which also contains trait for your models that will let you generate ULID ids for your Eloquent models automatically. Based on [robinvdvleuten/php-ulid](https://github.com/robinvdvleuten/php-ulid).

### What is a ULID?

[](#what-is-a-ulid)

In many cases universally unique identifier (UUID) can be suboptimal for many uses-cases because:

- It isn't the most character efficient way of encoding 128 bits of randomness
- UUID v1/v2 is impractical in many environments, as it requires access to a unique, stable MAC address
- UUID v3/v5 requires a unique seed and produces randomly distributed IDs, which can cause fragmentation in many data structures
- UUID v4 provides no other information than randomness which can cause fragmentation in many data structures

Instead, ULID offers:

- 128-bit compatibility with UUID
- 1.21e+24 unique ULIDs per millisecond
- Lexicographically sortable!
- Canonically encoded as a 26 character string, as opposed to the 36 character UUID
- Uses Crockford's base32 for better efficiency and readability (5 bits per character)
- Case insensitive
- No special characters (URL safe)

You can read more [here](https://github.com/alizain/ulid)

### What are the benefits?

[](#what-are-the-benefits)

1. With distributed systems you can be pretty confident that the primary key’s will never collide.
2. When building a large scale application when an auto increment primary key is not ideal.
3. It makes replication trivial (as opposed to int’s, which makes it REALLY hard)
4. Safe enough doesn’t show the user that you are getting information by id, for example `https://example.com/item/10`

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

[](#installation)

You can install this package via composer using this command:

```
 composer require linshunwei/laravel-ulid:^3.0
```

#### Laravel 5.5+

[](#laravel-55)

There is nothing else to do as the service provider and facade are going to be automaticaly discovered.

#### Laravel 5.3 and 5.4

[](#laravel-53-and-54)

You must install the service provider and facade:

```
// config/app.php
'providers' => [
    ...
    Linshunwei\Ulid\UlidServiceProvider::class,
];

...

'aliases' => [
    ...
    'Ulid' => Linshunwei\Ulid\Facades\Ulid::class,
];
```

Usage
-----

[](#usage)

### Migrations

[](#migrations)

When using the migration you should change $table-&gt;increments('id') to:

```
$table->char('id', 26)->primary();
```

> Simply, the schema seems something like this.

```
Schema::create('items', function (Blueprint $table) {
  $table->char('id', 26)->primary();
  ....
  ....
  $table->timestamps();
});
```

If the related model is using an ULID, the column type should reflect that also.

```
Schema::create('items', function (Blueprint $table) {
  $table->char('id', 26)->primary();
  ....
  // related model that uses ULID
  $table->char('category_id', 26);
  $table->foreign('category_id')->references('id')->on('categories');
  ....
  $table->timestamps();
});
```

### Models

[](#models)

To set up a model to use ULID, simply use the HasUlid trait.

```
use Illuminate\Database\Eloquent\Model;
use Linshunwei\Ulid\HasUlid;

class Item extends Model
{
  use HasUlid;
}
```

### Controller

[](#controller)

When you create a new instance of a model which uses ULIDs, this package will automatically add ULID as id of the model.

```
// 'HasUlid' trait will automatically generate and assign id field.
$item = Item::create(['name' => 'Awesome item']);
echo $item->id;
// 01brh9q9amqp7mt7xqqb6b5k58
```

Support
-------

[](#support)

If you believe you have found an issue, please report it using the [GitHub issue tracker](https://github.com/rorecek/laravel-ulid/issues), or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!

License
-------

[](#license)

The MIT License (MIT). [Pavel Rorecek](https://laravelist.com)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance82

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.1% 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 ~0 days

Total

2

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3fe2545ef1e7a6237d40d28020530c2f32f22a7f35993bc55e2a1baa2ab983ae?d=identicon)[linshunwei](/maintainers/linshunwei)

---

Top Contributors

[![rorecek](https://avatars.githubusercontent.com/u/6564004?v=4)](https://github.com/rorecek "rorecek (20 commits)")[![linshunwei](https://avatars.githubusercontent.com/u/9962608?v=4)](https://github.com/linshunwei "linshunwei (4 commits)")[![richardnbanks](https://avatars.githubusercontent.com/u/399107?v=4)](https://github.com/richardnbanks "richardnbanks (1 commits)")[![vov41knk](https://avatars.githubusercontent.com/u/2713991?v=4)](https://github.com/vov41knk "vov41knk (1 commits)")[![Xatta-Trone](https://avatars.githubusercontent.com/u/22274105?v=4)](https://github.com/Xatta-Trone "Xatta-Trone (1 commits)")

---

Tags

uuididentifierguidulid

### Embed Badge

![Health badge](/badges/linshunwei-laravel-ulid/health.svg)

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

###  Alternatives

[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k700.2M3.3k](/packages/ramsey-uuid)[pascaldevink/shortuuid

PHP 7.4+ library that generates concise, unambiguous, URL-safe UUIDs

5951.8M15](/packages/pascaldevink-shortuuid)[keiko/uuid-shortener

A simple shortener library for RFC 4122 compatible UUIDs. Change your 36 chars long UUID into it's shorter equivalent.

150215.4k2](/packages/keiko-uuid-shortener)[identifier/identifier

Common Interfaces and Factories for Identifiers

3226.2k1](/packages/identifier-identifier)[oittaa/uuid

A small PHP class for generating RFC 9562 universally unique identifiers (UUID) from version 3 to version 8.

50302.7k5](/packages/oittaa-uuid)[ramsey/identifier

A PHP library for generating and working with identifiers, including UUIDs, ULIDs, and Snowflakes

603.0k1](/packages/ramsey-identifier)

PHPackages © 2026

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