kblais/laravel-uuid

A simple library to use UUIDs as your Eloquent model's primary key.
86,135 10
Install
composer require kblais/laravel-uuid
Latest Version:v2.3.0
PHP:^8.0
License:MIT
Last Updated:Mar 24, 2025
Links: GitHub  ·  Packagist
Maintainer: kblais

laravel-uuid Build Status

A simple library to use UUIDs as your Eloquent model's primary key.

Why should I use UUIDs ?

To answer this question, I simply recommend you read this blog post.

OK, I'm convinced now. How do I install this ?

Require this package with Composer :

composer require kblais/laravel-uuid
  • the package internally use ramsey/uuid to generate the UUIDs.

Usage

First, your model's column must be a 36 characters column :

  • Laravel v4
$table->char('id', 36);
$table->primary('id');
  • Laravel v5+
$table->uuid('id');
$table->primary('id');

Then, just add the Kblais\Uuid\Uuid trait to your model, and you're done :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Kblais\Uuid\Uuid;

class User extends Model
{
    use Uuid;
}

Version 4 UUIDs are used by default. You can change this by overriding the $uuidVersion & $uuidString variables. For example :

protected $uuidVersion = 1;
protected $uuidString  = ''; // only needed when $uuidVersion is "3 or 5"

The supported UUIDs versions here are "1, 3, 4 and 5".

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

584,532,650 34,931
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

391,429,217 4,660