PHPackages                             shikachuu/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. shikachuu/laravel-cuid2

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

shikachuu/laravel-cuid2
=======================

First class support for CUID2 in your Laravel application

1.0.0(2y ago)3126MITPHPPHP ^8.1

Since Nov 26Pushed 2y ago1 watchersCompare

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

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

Laravel CUID2
=============

[](#laravel-cuid2)

The missing [CUID2](https://github.com/paralleldrive/cuid2#why) implementation for your Laravel apps.

Secure, collision-resistant ids, basically the next generation UUIDs.

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

[](#installation)

You can install the package via `composer`:

```
composer require shikachuu/laravel-cuid2
```

You can publish the configuration file with:

```
php artisan vendor:publish --provider="Shikachuu\LaravelCuid2\Cuid2ServiceProvider"
```

The configuration file will be published in `config/cuid2.php`, in this file you can change the default `key-length`which is set to `24` by default.

Usage
-----

[](#usage)

### Basic usage via Facade or a helper function

[](#basic-usage-via-facade-or-a-helper-function)

This is the simplest way to create a new CUID2 in your Laravel app.

You can use the provided facades and a helper function:

```
$id = cuid2();
// or provide an argument with the key size
$id = cuid2(30);
// or call the facade directly
$idFromTheFacade = \Shikachuu\LaravelCuid2\Facades\Cuid2::generate(30);
```

Now let's validate our example above:

```
\Shikachuu\LaravelCuid2\Facades\Cuid2::validate($id);
```

### Validation

[](#validation)

You can use the provided `cuid2` validation rule in the default [Laravel's Validator](https://laravel.com/docs/10.x/validation#validation-quickstart):

```
Validator::validate(['cuid' => 'qo08kg4ogogcc4sowwskkwko'], ['cuid' => 'cuid2']);
```

### Migrations

[](#migrations)

You can use `cuid2` and `foreignCuid2` as field types in your migrations:

```
