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(8mo ago)012MITPHPPHP ^8.4CI passing

Since Aug 18Pushed 8mo 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 1mo ago

READMEChangelogDependencies (6)Versions (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

30

—

LowBetter than 64% of packages

Maintenance58

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

267d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c618733e5efb2610f77c8cc30ffd6a17a19517996a70f605878e76c06fd8c13c?d=identicon)[cbenjafield](/maintainers/cbenjafield)

---

Top Contributors

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

---

Tags

laravelidsnano-id

###  Code Quality

TestsPest

Code StyleLaravel Pint

### 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

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[dcblogdev/laravel-junie

Install pre-configured guides for Jetbrains Junie

392.5k](/packages/dcblogdev-laravel-junie)

PHPackages © 2026

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