Use both auto-increment and UUID

v0.0.6 2018-02-19 12:38 UTC

This package is auto-updated.

Last update: 2023-12-06 22:52:39 UTC



Why choose between Seq ID (aka auto-increment) and UUID when you can use both? This package helps you to add UUID to your Laravel Models.

You can also use this class if you only wants UUID without increments.

Quick start

Install with composer:

composer require rap2hpoutre/has-uuid

Add the trait to your models:

class User {
    use \Rap2hpoutre\HasUuid\HasUuid;
    // ...

Use the Trait to load your models:

$user = User::uuid('e3ae1e6b-fabb-4839-bf65-de9a892c0d56');

And when you save a model, it will magically add a UUID to it:

$user = new User;
$user->name = 'raph';
$user->save(); // <- Your user has now a UUID (and a ID if you have not removed it)

PS: don't forget to add the UUID in your migrations:

   class CreateSesNotificationsTable extends \Illuminate\Database\Migrations\Migration
       public function up()
           \Schema::create('user', function ($table) {
               $table->uuid('uuid')->index(); // <- THIS.
       // ...