PHPackages                             parables/laravel-model-nanoid - 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. [Database &amp; ORM](/categories/database)
4. /
5. parables/laravel-model-nanoid

ActiveLibrary[Database &amp; ORM](/categories/database)

parables/laravel-model-nanoid
=============================

This package allows you to easily work with NanoID in your Laravel models.

v1.0.2(1y ago)194.3k↓39.3%3[1 issues](https://github.com/Parables/laravel-model-nanoid/issues)MITPHPPHP ^8.1

Since Mar 23Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/Parables/laravel-model-nanoid)[ Packagist](https://packagist.org/packages/parables/laravel-model-nanoid)[ RSS](/packages/parables-laravel-model-nanoid/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (4)Used By (0)

Laravel Model UUIDs
===================

[](#laravel-model-uuids)

Introduction
------------

[](#introduction)

Huge thanks to Micheal Dyrynda, whose work inspired me to create this package based on [laravel-model-nanoid](https://github.com/michaeldyrynda/laravel-model-uuid) but uses NanoId instead of UUID.

Why NanoID?
-----------

[](#why-nanoid)

[![npm trends](nmp_trends.png)](nmp_trends.png)

[![Nano ID logo by Anton Lovchikov](https://camo.githubusercontent.com/682f981e83617354735ab5431235d4b06580ad5fc9eb24baca0a8c04e5734697/68747470733a2f2f61692e6769746875622e696f2f6e616e6f69642f6c6f676f2e737667)](https://camo.githubusercontent.com/682f981e83617354735ab5431235d4b06580ad5fc9eb24baca0a8c04e5734697/68747470733a2f2f61692e6769746875622e696f2f6e616e6f69642f6c6f676f2e737667)

A tiny, secure, URL-friendly, unique string ID generator for PHP.

This package is PHP implementation of [ai's](https://github.com/ai) [nanoId](https://github.com/ai/nanoid). Read its documentation for more information.

- **Fast.** It is faster than NanoID.
- **Safe.** It uses cryptographically strong random APIs. Can be used in clusters.
- **Compact.** It uses a larger alphabet than NanoID (`A-Za-z0-9_-`). So ID size was reduced from 36 to 21 symbols.
- **Customizable.** Size, alphabet and Random Bytes Generator may be overridden.

> **Note**: this package explicitly does not disable auto-incrementing on your Eloquent models. In terms of database indexing, it is generally more efficient to use auto-incrementing integers for your internal querying. Indexing your `nanoId` column will make lookups against that column fast, without impacting queries between related models.

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

[](#installation)

This package is installed via [Composer](https://getcomposer.org/). To install, run the following command.

```
composer require parables/laravel-model-nanoid
```

Code Samples
------------

[](#code-samples)

In order to use this package, you simply need to import and use the trait within your Eloquent models.

```
