PHPackages                             parables/laravel-cuid2 - 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-cuid2

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

parables/laravel-cuid2
======================

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

v1.0.3(11mo ago)75.0k—0%[2 issues](https://github.com/Parables/laravel-cuid2/issues)MITPHP

Since Mar 23Pushed 11mo agoCompare

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

READMEChangelog (3)Dependencies (5)Versions (5)Used By (0)

laravel-cuid2
=============

[](#laravel-cuid2)

> Note: This package uses [Cuid2](https://github.com/visus-io/php-cuid2) as the initial version is deprecated.
>
> **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 `cuid` column will make lookups against that column fast, without impacting queries between related models.

Secure, collision-resistant ids optimized for horizontal scaling and performance. Next generation UUIDs.

Need unique ids in your app? Forget UUIDs and GUIDs which often collide in large apps. Use Cuid2, instead.

**Cuid2 is:**

- **Secure:** It's not feasible to guess the next id, existing valid ids, or learn anything about the referenced data from the id. Cuid2 uses multiple, independent entropy sources and hashes them with a security-audited, NIST-standard cryptographically secure hashing algorithm (Sha3).
- **Collision resistant:** It's extremely unlikely to generate the same id twice (by default, you'd need to generate roughly 4,000,000,000,000,000,000 ids ([`sqrt(36^(24-1) * 26) = 4.0268498e+18`](https://en.wikipedia.org/wiki/Birthday_problem#Square_approximation)) to reach 50% chance of collision.)
- **Horizontally scalable:** Generate ids on multiple machines without coordination.
- **Offline-compatible:** Generate ids without a network connection.
- **URL and name-friendly:** No special characters.
- **Fast and convenient:** No async operations. Won't introduce user-noticeable delays. Less than 5k, gzipped.
- **But not *too fast*:** If you can hash too quickly you can launch parallel attacks to find duplicates or break entropy-hiding. For unique ids, the fastest runner loses the security race.

**Cuid2 is not good for:**

- Sequential ids (see the [note on K-sortable ids](https://github.com/paralleldrive/cuid2#note-on-k-sortablesequentialmonotonically-increasing-ids), below)
- High performance tight loops, such as render loops (if you don't need cross-host unique ids or security, consider a simple counter for this use-case, or try [Ulid](https://github.com/ulid/javascript) or [NanoId](https://github.com/ai/nanoid)).

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

[](#installation)

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

```
composer require parables/laravel-cuid2
```

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

[](#code-samples)

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

```
