- How do I install ryangjchandler/laravel-uuid?
- Install it with Composer using composer require ryangjchandler/laravel-uuid. The package has no service provider or configuration to publish, so installation is limited to pulling the dependency and applying its trait to the models that should use UUIDs. Check the package's composer.json for PHP and Laravel version constraints before adding it to an existing project.
- Does this package work with Laravel 9, 10, and 11?
- The package is a small trait around Eloquent model boot hooks, so it can work on supported Laravel versions where the trait API is unchanged. However, Laravel 9 and later ship native HasUuids and HasUlids traits, which make this package functionally redundant for most new projects. Verify the package's declared illuminate/database constraint on Packagist before assuming compatibility with your target Laravel release.
- How do I use the UUID trait on an Eloquent model?
- Add the package's UUID trait to the model class alongside Laravel's base Model, typically with a use statement inside the class body. On model creation, the trait's boot hook assigns a UUID to the configured attribute, usually the primary key. You should also ensure the model's key type and incrementing settings match a non-integer, non-auto-incrementing primary key.
- Do I need to change my migration column type to use UUIDs?
- Yes. A UUID primary key requires a migration column such as uuid or char(36) rather than an auto-incrementing big integer. Any foreign keys referencing that table must use the same column type and length. The package handles value generation in PHP, not schema changes, so migrations remain your responsibility.
- Does the package support route model binding with UUIDs?
- The package is described as resolving models by UUID, which fits Laravel's route model binding when the model's primary key is a UUID. You should confirm that route definitions and controller signatures resolve correctly in your application, especially if you customize getRouteKeyName or use implicit binding. Testing route binding on a pilot model is the safest way to validate behavior.
- What UUID version does this package generate, v4 or v7?
- The package's implementation centers on Laravel's Str::uuid() helper, which generates random UUIDv4 values. There is no indication that it supports ordered UUIDv7 or ULID-style generation, which matters for index locality at scale. If ordered identifiers are a requirement, evaluate Laravel's newer native UUID traits or a dedicated UUIDv7 package instead.
- Can I add UUIDs to an existing table with integer primary keys?
- The package is not a migration tool, so changing an existing integer primary key to a UUID is a separate schema migration project. You must retype foreign keys, audit joins and whereIn queries, update factories and seeders, and verify route bindings and API serialization. A safe path is to add a nullable UUID column, backfill it, dual-write, swap keys, and then drop the old integer column.
- Is ryangjchandler/laravel-uuid maintained and safe for production?
- The package has no visible dependents, which is a warning sign for long-term maintenance and future Laravel compatibility. The code surface is small and low-risk, but an unmaintained trait can break silently on a future Laravel upgrade. For production, prefer Laravel's native HasUuids on Laravel 9 or later unless you have a specific reason to use this package.
- How does this package compare to Laravel's built-in HasUuids trait?
- Laravel 9 introduced HasUuids, which generates UUID primary keys using the framework's own model lifecycle hooks. This package predates or duplicates that convenience with a single trait and no additional capabilities such as UUIDv7 ordering. If you are already on Laravel 9 or newer, adopting HasUuids avoids a third-party dependency and follows the framework's supported path.
- Does the package support binary(16) UUID storage or UUID foreign keys?
- The package appears to assign string UUIDs generated by Str::uuid(), which suits uuid or char(36) columns rather than compact binary(16) storage. There is no documented hook for binary packing or unpacking, so binary storage would require custom casting outside the package. Foreign keys referencing UUID primary keys are a database concern and must be defined with matching column types in your migrations.