PHPackages                             timyouri/laravel-customid - 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. timyouri/laravel-customid

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

timyouri/laravel-customid
=========================

Eloquent custom ID generation trait for Laravel 6 and above.

1.0.2(3y ago)013MITPHPPHP ^7.4|^8.0|^8.1|^8.2

Since Oct 27Pushed 3y agoCompare

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

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

[![Total Downloads](https://camo.githubusercontent.com/d83a8bc4b8cb671569927efa4cdb83ac2dbfeb2130e5bb84aca9301773534bff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74696d796f7572692f6c61726176656c2d637573746f6d69642e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/timyouri/laravel-customid)[![MIT licensed](https://camo.githubusercontent.com/31e62e0eff03ce9ddfdf69d8476340d4f541990bfb152cb02a0f342965252997/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/JamesHemery/laravel-uuid/master/LICENSE)

laravel-customid
================

[](#laravel-customid)

> **Note**
>
> laravel now supports using UUID's and custom ID's by default. Check out [their documentation](https://laravel.com/docs/9.x/eloquent#uuid-and-ulid-keys) to see if it fits your needs.

Eloquent custom ID generation trait for Laravel 6 and above.

A simple trait that allows you to generate and lock a (unique) custom generated id.

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

[](#installation)

```
composer require timyouri/laravel-customid

```

Usage
-----

[](#usage)

### In your migrations

[](#in-your-migrations)

Prepare your migration(s) where you would like to use random ID's. It would be best when creating the table, because updating a table may not work for you as it will most likely require you to use `->default()` or `->nullable()`.

```
// Example of 2014_10_12_000000_create_users_table.php:

Schema::create('users', function (Blueprint $table) {
-   $table->id();
+   $table->string('id')->primary()->unique();
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});
```

### In your models

[](#in-your-models)

#### Basic usage

[](#basic-usage)

The basic usage is just using the trait and and setting the keytype and it will automatically generate random ID's for you.

```
