Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Auto Create Uuid Laravel Package

mindtwo/laravel-auto-create-uuid

Auto-fill a UUID v4 on Eloquent models when creating or replicating. Add a trait, add a uuid column, and it just works—no config. Supports custom UUID column names and ensures replicas get a fresh UUID by excluding the UUID attribute on replicate.

View on GitHub
Deep Wiki
Context7

Laravel Auto Create UUID

Latest Stable Version run-tests PHPStan Total Downloads License

Automatically populate a UUID column on Eloquent models when they are created or replicated. Drop the trait onto any model and the rest works without configuration.

Installation

Install the package via Composer:

composer require mindtwo/laravel-auto-create-uuid

Requirements

  • PHP 8.2+
  • Laravel 10, 11, 12, or 13

Usage

Add the trait to a model

use Illuminate\Database\Eloquent\Model;
use mindtwo\LaravelAutoCreateUuid\AutoCreateUuid;

class Example extends Model
{
    use AutoCreateUuid;
}

Add a UUID column to the migration

$table->uuid('uuid')->unique();

The trait listens to the creating and replicating model events and fills the configured UUID column with a new UUID v4 whenever the column is empty or holds an invalid UUID.

Customize the UUID column

The default column name is uuid. To use a different column, either define a $uuid_column property:

class Example extends Model
{
    use AutoCreateUuid;

    protected string $uuid_column = 'identifier';
}

or override the getUuidColumn() method:

class Example extends Model
{
    use AutoCreateUuid;

    public function getUuidColumn(): string
    {
        return 'identifier';
    }
}

Replicating models

The trait overrides Model::replicate() to ensure the UUID column is excluded from the cloned attributes, so the replica receives a fresh UUID via the replicating event.

Testing

composer test

Static analysis

composer analyse

Code style

composer format

Changelog

Please see CHANGELOG for a list of recent changes.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@mindtwo.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky