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

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

pelmered/laravel-ulid
=====================

Universally Unique Lexicographically Sortable Identifier(ULID) for Laravel

v0.1.0(11mo ago)11.5kMITPHPPHP ^8.4CI passing

Since Nov 24Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/pelmered/Laravel-ULID)[ Packagist](https://packagist.org/packages/pelmered/laravel-ulid)[ GitHub Sponsors](https://github.com/pelmered)[ Fund](https://ko-fi.com/pelmered)[ RSS](/packages/pelmered-laravel-ulid/feed)WikiDiscussions main Synced 1mo ago

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

Laravel-ULID
============

[](#laravel-ulid)

This package improves the ULID support in Laravel with the following features:

- Configurable prefix
- Configurable length (both time and random parts)
- Configurable formatting/case
- Configurable time source
- Configurable randomness source
- Provides a Facade for working with ULIDs

ULIDs - What and why
--------------------

[](#ulids---what-and-why)

ULIDs are a compact, time-ordered, globally unique identifier that are used to identify resources in a way that is both human-readable and machine-readable.

For a more in-depth technical explanation, see the [ULID specification](https://github.com/ulid/spec)

One of my personal favorite things about ULIDs is that you can double-click on them to select and copy. Try to select and copy these IDs: `u_01ARZ3NDEKTSV4RRFFQ69G5FAVY` and `4f839b45-fcca-495b-b9ed-0e365270b1c3`. The prefixes also makes it immediately clear what kind of ID it is when you see it.

This is great when you are passing IDs around to colleagues or coworkers when debugging or working with support. The hyphens also look pretty ugly and do not have any real meaning for a human.

---

[![Latest Stable Version](https://camo.githubusercontent.com/bb026da845ccf775ed583fd74905e9d661b10cc2f575ad0a6e8aef6ad8847a92/68747470733a2f2f706f7365722e707567782e6f72672f70656c6d657265642f6c61726176656c2d756c69642f762f737461626c65)](https://packagist.org/packages/pelmered/laravel-ulid)[![Total Downloads](https://camo.githubusercontent.com/3e6f922028056ef1520f887c05cdbaf1c773202c79f7e73c87eae95cf6633f39/68747470733a2f2f706f7365722e707567782e6f72672f70656c6d657265642f6c61726176656c2d756c69642f642f746f74616c)](//packagist.org/packages/pelmered/laravel-ulid)[![Monthly Downloads](https://camo.githubusercontent.com/6b3d29fbbb62af545145ffa127dbf182440f0c5fbac01a0e36fbe717315452a2/68747470733a2f2f706f7365722e707567782e6f72672f70656c6d657265642f6c61726176656c2d756c69642f642f6d6f6e74686c79)](//packagist.org/packages/pelmered/laravel-ulid)[![License](https://camo.githubusercontent.com/1459e24bee28951ced6271169aadc3054b958fbaf7aa4c559217a1f1a18379a2/68747470733a2f2f706f7365722e707567782e6f72672f70656c6d657265642f6c61726176656c2d756c69642f6c6963656e7365)](https://packagist.org/packages/pelmered/laravel-ulid)

[![Tests](https://github.com/pelmered/laravel-ulid/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/pelmered/laravel-ulid/actions/workflows/run-tests.yml)[![OtterWise Coverage](https://camo.githubusercontent.com/649452181a382fc39660a4df397bf26f9454838e0db771728b9e3d9012f17d0b/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6f74746572776973652e6170702f62616467652f6769746875622f70656c6d657265642f6c61726176656c2d756c6964)](https://otterwise.app/github/pelmered/laravel-ulid)[![OtterWise Type Coverage](https://camo.githubusercontent.com/715ca3e8d64e5c85e07e7c30fed765cb5a01d13c89dcfbbc4a4edf1080056cf5/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6f74746572776973652e6170702f62616467652f6769746875622f70656c6d657265642f6c61726176656c2d756c69642f74797065)](https://otterwise.app/github/pelmered/laravel-ulid)

[![Tested on PHP 8.4](https://camo.githubusercontent.com/80ba7033bfaa77220a79982be9b5229de191359a5626b258558042f2e6a9ec99/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5465737465642532306f6e2532305048502d253230382e342d627269676874677265656e2e7376673f6d61784167653d32343139323030)](https://github.com/pelmered/filament-money-field/actions/workflows/tests.yml)[![Tested on OS:es Linux, MacOS, Windows](https://camo.githubusercontent.com/9926c282f083c7a73d0e09f2ebd3b679617d43ce70c34e8fc09029fa10025f74/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5465737465642532306f6e2532306c61737465737425323076657273696f6e732532306f662d2532305562756e74752532302537432532304d61634f5325323025374325323057696e646f77732d627269676874677265656e2e7376673f6d61784167653d32343139323030)](https://github.com/pelmered/laravel-ulid/actions/workflows/tests.yml)

TODO
----

[](#todo)

- Add more tests
- Add docs
- Add license
- Add badges
- Implement custom formatter support

Roadmap
-------

[](#roadmap)

- Migration tool for migrating an existing database with numeric or UUIDs to ULIDs. Probably as a separate suggested package.

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

[](#installation)

```
composer require pelmered/laravel-ulid
```

Setup
-----

[](#setup)

Add the interface `Ulidable` and the trait `HasUlid` to your model.

```
use Pelmered\LaravelUlid\LaravelUlidServiceProvider;
class Post extends Model implements Ulidable
{
    use HasUlid;

    //...
}
```

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

[](#configuration)

You can configure the ULID prefix, time length and random length in the model.

```
use Pelmered\LaravelUlid\LaravelUlidServiceProvider;use Pelmered\LaravelUlid\ValueObject\Ulid;
class Post extends Model implements Ulidable
{
    use HasUlid;

    protected string $ulidPrefix = 'p_';
    protected int $ulidTimeLength = 10;
    protected int $ulidRandomLength = 16;
    protected string $ulidOptions = Ulid::OPTION_UPPERCASE;

    //...
}
```

You probably shouldn't touch the time length unless you know what you are doing.
The Random part could be optimized based on your needs. A low traffic application could probably use a shorter random part to optimize storage space and performance.

Usage (Work in progress)
------------------------

[](#usage-work-in-progress)

### Migrations

[](#migrations)

To create a ULID column in a migration, you can use the `ulid` or `modelULid` methods like this to get the correct length.

```
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Create a table with an ULID primary key like this:
        Schema::create('users', function (Blueprint $table) {
            $table->uLid('id', (new \Workbench\App\Models\User())->getUlidLength())->primary();
        });
        // or like this:
        Schema::create('posts', function (Blueprint $table) {
            $table->modelULid('id', User::class)->primary();
        });
    }
}
```

### Facade

[](#facade)

```
ULID::make(); // '1234567890123456789' - Normal ULID
ULID::make('p_', Carbon::parse('2010-11-12 01:02:03')); // 'u_1234567890123456789' - ULID with prefix
ULID::make('p_', 10, 10 ); // 'u_1234567890123456789' - ULID with prefix
ULID::fromModel($model);
ULID::isValidUlid('u_1234567890123456789', $model);
```

### Formatting

[](#formatting)

```
```

### Config

[](#config)

Publish the config file `config/ulid.php` to your project.

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

Running tests
-------------

[](#running-tests)

Run the test with `vendor/bin/pest` or `composer test`.

The test suite has some tests that require a MySQL database. To run these tests, you need to create a `.env` file in the root of the project with the following contents, adjusted for your setup:

```
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_ulid_testing
DB_TESTING_DATABASE=laravel_ulid_testing
DB_USERNAME=root
DB_PASSWORD=
```

You can also skip the MySQL tests the tests by running `vendor/bin/pest --exclude-group=mysql`.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance56

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

342d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/680058?v=4)[Peter Elmered](/maintainers/pelmered)[@pelmered](https://github.com/pelmered)

---

Top Contributors

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

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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