ddlabs / uuid-package
Package to allow you to use UUID for primary key in Laravel Models
Installs: 6 678
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 0
pkg:composer/ddlabs/uuid-package
Requires
- php: ^7.0|^8.0
 - webpatser/laravel-uuid: ^3.0
 
This package is auto-updated.
Last update: 2025-10-18 20:50:29 UTC
README
DiegoLabs UUID Package
Simple package to allow you to add UUID to Laravel Models via a trait.
Install
 composer require ddlabs/uuid-package
Traits
- SetsUuidWhenCreating - This sets the primary key of the model to a UUID. It allows you to pass a UUID if you have a workflow that creates a UUID by default. If the UUID is version 4 compliant, then the trait will just us the UUID passed to it. We use this from time to time when records are created on a mobile device then passed to a backend via an API. They may already have a UUID associated with it.
 
Usage
ID must be configured in the database to accept a UUID.
For Migrations:
public function up()
{
    Schema::create('your_models', function (Blueprint $table) {
        $table->uuid('id'); // Set to uuid
        $table->string('name');
        $table->timestamps();
        $table->primary('id'); // Add primary key
    });
}
For Models:
use Ddlabs\Uuid\Traits\SetsUuidWhenCreating;
class YourModel extends Model
{
    use SetsUuidWhenCreating;
    public $incrementing = false;
    protected $keyType = 'string';
   ...
}