Weave 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

Has Uuid Laravel Package

rap2hpoutre/has-uuid

A lightweight Laravel trait that automatically assigns UUIDs to Eloquent models, replacing or supplementing auto-incrementing IDs. Just add the trait and configure the column to get collision-safe unique identifiers on model creation with minimal setup.

View on GitHub
Deep Wiki
Context7

Add UUID to your Laravel Models in a breeze

Frequently asked questions about Has Uuid
How do I install rap2hpoutre/has-uuid in a Laravel project?
Install it with Composer using composer require rap2hpoutre/has-uuid. Then make sure your Eloquent model has the UUID column configured in its database table before enabling the trait. Composer will register the package for your Laravel app.
How do I add UUIDs to an Eloquent model with the HasUuid trait?
Import the package's HasUuid trait and add use HasUuid inside your model class. The trait hooks into model creation and assigns a UUID automatically when the model is saved. You still need a matching UUID column in the table and any key configuration your model requires.
Does has-uuid replace the default auto-incrementing primary key?
It can replace auto-incrementing IDs when your model and migration are set up to use a UUID as the primary key. It can also supplement an existing integer ID by writing the UUID to a separate column. The package does not change your schema for you, so you must configure the column and model key settings.
What database migration changes are needed for UUID primary keys?
Add a UUID column or change the primary key column to a UUID-compatible type, such as uuid or char(36), depending on your database. If the UUID is the primary key, set the model's key type to string and disable incrementing. Also add a unique index if your schema does not already enforce uniqueness.
Which Laravel versions are supported by rap2hpoutre/has-uuid?
Supported Laravel versions are defined by the package's Composer constraints, so check composer.json before installing. Because the trait depends on Eloquent model events, verify it on your target Laravel version. If you are upgrading Laravel, run your model tests after the Composer update.
Can I keep an integer ID and also store a UUID with this package?
Yes, the package is described as replacing or supplementing auto-incrementing IDs. You can keep your existing integer primary key and add a separate UUID column for public-facing identifiers. Make sure that UUID column is unique and that the trait is pointed at the correct attribute if configuration is required.
How does has-uuid generate UUIDs and avoid collisions?
The package assigns a UUID to the model on creation using UUID generation that is intended to be collision-safe. You should still enforce uniqueness at the database level with a unique index. Do not rely only on application code for uniqueness guarantees.
Is rap2hpoutre/has-uuid safe to use in production?
It is a lightweight trait for assigning UUIDs on model creation, so it can be suitable for production when your schema and indexes are correct. Test migrations, UUID column types, and unique constraints in staging before deploying. Also confirm the package's Composer constraints match your Laravel and PHP versions.
How do I test Eloquent models that use the HasUuid trait?
Use Laravel's testing helpers with a test database and create a model through Eloquent. Assert that the UUID attribute is populated, is a valid UUID format, and is unique across records. If UUID is the primary key, also assert the model reports string keys and non-incrementing behavior.
What are alternatives to has-uuid for UUIDs in Laravel?
Laravel's Str::uuid() helper and model events can generate UUIDs without an extra package. You can also use framework features or other UUID traits/packages if you need ULIDs, ordered UUIDs, or more configuration. Choose based on whether you need a minimal trait or broader UUID tooling.
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator