PHPackages                             jdavidbakr/ulidmodelroutes - 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. jdavidbakr/ulidmodelroutes

ActiveLibrary

jdavidbakr/ulidmodelroutes
==========================

Configures models to have ULID route keys while still having integer primary keys

1.0(today)017↑2547.1%MITPHPPHP ^8.3CI passing

Since Jul 28Pushed todayCompare

[ Source](https://github.com/jdavidbakr/ulidmodelroutes)[ Packagist](https://packagist.org/packages/jdavidbakr/ulidmodelroutes)[ Docs](https://github.com/jdavidbakr/ulidmodelroutes)[ GitHub Sponsors](https://github.com/jdavidbakr)[ RSS](/packages/jdavidbakr-ulidmodelroutes/feed)WikiDiscussions main Synced today

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

Ulidmodelroutes
===============

[](#ulidmodelroutes)

 [![Packagist](https://camo.githubusercontent.com/644d676ba108d53db1ccab2c207cdb9f6037c804e18e7a4fcc3791b4da0f54ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a646176696462616b722f756c69646d6f64656c726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdavidbakr/ulidmodelroutes) [![PHP from Packagist](https://camo.githubusercontent.com/bf0f54ef11cde89204b6f47dd385723c23e71cc60cb40afd841eaef366d9cb13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a646176696462616b722f756c69646d6f64656c726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdavidbakr/ulidmodelroutes) [![Laravel versions](https://camo.githubusercontent.com/bb4eb7c544607e15c908b78d8821e654203ed7a337ec73eed6bdf55932c37436/68747470733a2f2f62616467652e6c61726176656c2e636c6f75642f62616467652f6a646176696462616b722f756c69646d6f64656c726f757465733f7374796c653d666c6174)](https://packagist.org/packages/jdavidbakr/ulidmodelroutes) [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/9fab74bcd60d9b041f27feda65577c1a785b3e78a3be45c74a81ce4b86c66573/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a646176696462616b722f756c69646d6f64656c726f757465732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/jdavidbakr/ulidmodelroutes/actions) [![Total Downloads](https://camo.githubusercontent.com/f784079d0aa377e6ac79fed89182b1c23c4f3e156d63cd0bd3a25a758949913a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a646176696462616b722f756c69646d6f64656c726f757465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdavidbakr/ulidmodelroutes)

Configures models to have ULID or UUID route keys while still having integer primary keys

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

[](#installation)

You can install the package via Composer:

```
composer require jdavidbakr/ulidmodelroutes
```

If you want to change the default ULID column name, publish the config file:

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

Usage
-----

[](#usage)

Add an identifier column to each model table that should be used for route model binding. Keep it indexed and unique.

For ULIDs:

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

Schema::table('posts', function (Blueprint $table) {
    $table->ulid('ulid')->nullable()->unique();
});
```

For UUIDs:

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

Schema::table('posts', function (Blueprint $table) {
    $table->uuid('uuid')->nullable()->unique();
});
```

Apply the trait to the model.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use jdavidbakr\UlidModelRoutes\HasUlidRouteKey;

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

Once the trait is applied:

- new models receive a route identifier automatically when they are created
- URL generation uses the configured route identifier instead of the integer primary key
- implicit route model binding resolves records by the configured route key column

Example route:

```
use App\Models\Post;
use Illuminate\Support\Facades\Route;

Route::get('/posts/{post}', function (Post $post) {
    return $post;
});
```

Example URL generation:

```
$post = Post::query()->first();

route('posts.show', $post);
// /posts/01K10R0X6T0B3R3D4Y8S0KQ7M4
```

### Customizing the column name per model

[](#customizing-the-column-name-per-model)

If a model should use a different route key column, define `ulidRouteKeyColumnName` on that model.

```
class Team extends Model
{
    use HasUlidRouteKey;

    protected ?string $ulidRouteKeyColumnName = 'public_id';
}
```

### Setting a package-wide default column

[](#setting-a-package-wide-default-column)

After publishing the config file, change the default column name:

```
return [
    'default_column_name' => 'public_id',
];
```

### Switching between ULID and UUID

[](#switching-between-ulid-and-uuid)

By default, the package generates ULIDs.

You can switch to UUID generation in the config file:

```
return [
    'id_type' => 'uuid', // 'ulid' or 'uuid'
    'uuid_type' => 'uuid7', // 'uuid7', 'uuid4', or 'ordered'
];
```

Notes:

- `ulid` keeps lexicographic ordering and supports `created_at`-based backfill timestamps.
- `uuid7` is time-ordered and also supports `created_at`-based backfill timestamps.
- `uuid4` is random and does not preserve chronological sort order.

### Existing data

[](#existing-data)

This package does not create database columns for you. If you are adding route identifiers to an existing table, add the column in a migration and then backfill missing values before making the column unique.

You can backfill an existing model with the included Artisan command:

```
php artisan ulidmodelroutes:backfill "App\\Models\\Post"
```

The command only fills missing route key values. When a row has a `created_at` value, the generated ULID or UUIDv7 uses that timestamp so the resulting identifiers stay as close as possible to the model's original creation order.

Recommended rollout for existing tables:

1. Add the nullable ULID column.
2. Run the backfill command for the model.
3. Verify all rows have values.
4. Add the unique index and, if desired, make the column non-nullable.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Thank you for considering contributing to UlidModelRoutes.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please open a private security advisory or contact the maintainer directly if you discover a vulnerability.

Credits
-------

[](#credits)

- [J David Baker](https://github.com/jdavidbakr)

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance100

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

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

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25177?v=4)[J David Baker](/maintainers/jdavidbakr)[@jdavidbakr](https://github.com/jdavidbakr)

---

Top Contributors

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

---

Tags

laraveljdavidbakrulidmodelroutes

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jdavidbakr-ulidmodelroutes/health.svg)

```
[![Health](https://phpackages.com/badges/jdavidbakr-ulidmodelroutes/health.svg)](https://phpackages.com/packages/jdavidbakr-ulidmodelroutes)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M348](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M250](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)

PHPackages © 2026

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