Eloquent UUID

Eloquent UUID

Eloquent UUID is a package by Matt Inamdar that is a simple drop-in solution for providing UUID (version 4) support for the IDs of your Eloquent models.

To use this package, your model needs to extend from the model class provided by this package:

<?php

namespace App\Models;

use GoldSpecDigital\LaravelEloquentUUID\Database\Eloquent\Model;

class BlogPost extends Model
{
    //
}

Note: the package also provides a model that satisfies the Authenticatable interface for the User model.

When you create a model, a UUID is automatically generated as the primary key:

// No UUID provided (automatically generated).
$model = Model::create();
echo $model->id; // abb034ae-fcdc-4200-8094-582b60a4281f

You can also specify your own UUID if you need to know the ID of the model before it’s created:

// UUID explicity provided.
$model = Model::create(['id' => '04d7f995-ef33-4870-a214-4e21c51ff76e']);
echo $model->id; // 04d7f995-ef33-4870-a214-4e21c51ff76e

You can learn more about this package, get full installation instructions, and view the source code on GitHub at goldspecdigital/laravel-eloquent-uuid.


Filed in: News


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Full Stack Software Engineer
Atlanta, GA or Remote
Voxie
Laravel/PHP Developer
Chicago, IL
Neon One
Software Engineer, Web Applications
Vaughan, ON, Canada
Blast Motion
Contract Services Software Engineer (Laravel | Vue | Tailwind)
Remote
Riverbed Technology
Senior Laravel Developer
Wilmington, NC
GE Software Inc.
Senior Full Stack Developer (PHP | Vue | DDD)
Charleston, SC
MassageBook