PHPackages                             cbenjafield/laravel-nano-ids - 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. cbenjafield/laravel-nano-ids

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

cbenjafield/laravel-nano-ids
============================

A Laravel package for adding Nano ID support to a Laravel application.

v0.0.1(10mo ago)012MITPHPPHP ^8.4CI passing

Since Aug 18Pushed 10mo agoCompare

[ Source](https://github.com/cbenjafield/laravel-nano-ids)[ Packagist](https://packagist.org/packages/cbenjafield/laravel-nano-ids)[ RSS](/packages/cbenjafield-laravel-nano-ids/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Nano ID
===============

[](#laravel-nano-id)

Attach Nano IDs to Laravel models using the [hidehalo/nanoid-php](https://github.com/hidehalo/nanoid-php) package.

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

[](#installation)

```
composer require cbenjafield/laravel-nano-ids
```

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

[](#configuration)

The package will work out of the box, but if you want to publish the configuration file, you can run:

```
php artisan vendor:publish --provider="Cbenjafield\LaravelNanoIds\NanoIdServiceProvider"
```

This will create a `config/nanoid.php` file where you can customise the default settings for Nano IDs, such as the mode and size.

Usage
-----

[](#usage)

### Model Setup

[](#model-setup)

Attach the `HasNanoId` trait to a model:

```
use Cbenjafield\LaravelNanoIds\HasNanoId;

// Optional: specify a custom length for the Nano ID
protected function getNanoIdSize(): int
{
    return 16; // Default is 21
}
```

By default the model's primary key field ('id') will be used for the Nano ID. If you want to use a different field, you can use [Laravel's `$primaryKey` properties](https://laravel.com/docs/12.x/eloquent#primary-keys):

```
use Illuminate\Database\Eloquent\Model;
use Cbenjafield\LaravelNanoIds\HasNanoId;

class MyModel extends Model
{
    use HasNanoId;

    protected $primaryKey = 'custom_id'; // Use 'custom_id' instead of 'id'
}
```

### Migrations

[](#migrations)

When creating a migration for a model that uses Nano IDs, you can use the `nanoId` and `primaryNanoId` methods to define the columns:

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

public function up()
{
    Schema::create('my_models', function (Blueprint $table) {
        $table->primaryNanoId('custom_id'); // Creates a primary key with Nano ID
        $table->nanoId('another_nano_id'); // Creates a regular Nano ID column
        $table->nanoId('nano_id_with_length', 16); // Creates a Nano ID with a custom length

        $table->string('name');
        $table->timestamps();
    });
}
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance54

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

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

320d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4989492?v=4)[Charlie Benjafield](/maintainers/cbenjafield)[@cbenjafield](https://github.com/cbenjafield)

---

Top Contributors

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

---

Tags

laravelidsnano-id

### Embed Badge

![Health badge](/badges/cbenjafield-laravel-nano-ids/health.svg)

```
[![Health](https://phpackages.com/badges/cbenjafield-laravel-nano-ids/health.svg)](https://phpackages.com/packages/cbenjafield-laravel-nano-ids)
```

###  Alternatives

[stephenjude/filament-blog

Filament Blog Builder

20619.4k](/packages/stephenjude-filament-blog)

PHPackages © 2026

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