- How do I add UUID auto-generation to an existing Laravel Eloquent model?
- Use the `AutoCreateUuid` trait in your model class and add a `uuid()` column to your migration. No additional configuration is needed—the package automatically generates UUIDs on model creation or replication.
- Does this package work with Laravel 9 or PHP 8.1?
- No, this package requires Laravel 10–13 and PHP 8.2+. If you're using an older version, you’ll need to upgrade or find an alternative solution.
- Can I customize the UUID column name beyond the default 'uuid'?
- Yes, you can override the column name by defining a `$uuid_column` property or implementing the `getUuidColumn()` method in your model.
- Will this package interfere with existing `replicate()` logic in my models?
- No, the package explicitly excludes the UUID column during replication, ensuring replicas get a fresh UUID while preserving other attributes.
- Does this package support bulk inserts or batch operations?
- No, this package generates UUIDs per-model-instance during `creating` or `replicating` events. For bulk inserts, you’ll need to handle UUID generation manually.
- What happens if I manually set a UUID before saving?
- The package checks if the UUID is valid using Laravel’s `Str::isUuid()`. If valid, it skips auto-generation and preserves your manually set value.
- Is there a performance impact when using this package?
- The package adds minimal overhead since UUID generation is lightweight. For high-throughput systems, ensure your database uses a binary(16) UUID column type for optimal performance.
- Can I use this with non-Eloquent models or raw database queries?
- No, this package is designed specifically for Eloquent models. For raw queries or non-Eloquent operations, you’ll need to generate UUIDs manually.
- Are there any known conflicts with other Laravel packages?
- Potential conflicts could arise if other packages override Eloquent’s `creating` or `replicating` events. Test in a staging environment to ensure compatibility.
- How do I migrate an existing table to use UUIDs without downtime?
- Add a new UUID column with a default value (e.g., `uuid()->default(db_raw('(uuid())'))`), then update your application to use the new column. Use a data migration to backfill UUIDs if needed.