jetcod/eloquent-keygen
Laravel package that integrates Snowflake ID generation with Eloquent models, giving you automatic, distributed, unique primary keys via a base model or trait, with per-model opt-out and configurable settings for scalable applications.
godruoyi/php-snowflake; this package is a trait, a service provider, and a config file that hooks Eloquent's creating event. So the real choice is whether roughly a trait's worth of glue is a pinned dependency or our own code. Both are cheap. The value of deciding once is that three teams don't ship three different ID conventions. Frame it internally as buying the convention, not the code.LAST_INSERT_ID() round-trips and auto-increment contention are the bottleneck. Without that number, this is architecture aesthetics, and it should lose the argument to anything customer-visible.Jetcod\Eloquent\Model, or apply the Snowflake trait) plus a per-model snowflake(): bool opt-out mean we can pilot on one non-critical service and revert model by model. That is a scoped experiment, not a primary-key referendum, and it should be written into the plan explicitly so nobody treats it as a one-way door.Consider it when:
worker_id / datacenter_id allocation. That ownership is the actual cost of entry, and it belongs to platform/ops, not the package. Misconfiguration produces silent collisions, not exceptions — which is a class of bug that surfaces months later as corrupted joins.Look elsewhere, or write the trait in-house, when:
BIGINT UNSIGNED migration work and operational overhead for no benefit.Three cheap pre-adoption checks to sequence before committing a date:
id column must be BIGINT UNSIGNED before rollout — a blocking schema change, plus a backfill or dual-write story for any legacy auto-increment rows.php artisan vendor:publish --provider="eloquent-key-generator-config" looks incorrect. Verify the real service provider name in source before it lands in a plan, a runbook, or a setup doc.saving to creating and sets the floor at 64-bit PHP 8.1+ with Laravel 10–13 (php-snowflake ≥3.2). Confirm our runtime matrix, and note that this is a behavioral change in a young package — a signal to re-read release notes on every bump rather than trusting semver.For executives: "There is a cheap, contained option to take the database out of the ID-generation path and remove a constraint on horizontal scaling. It's a small MIT-licensed Laravel add-on — roughly a two-line change per model — that generates globally unique IDs inside the application instead of asking the database for them.
The upside is concrete and measurable: fewer round-trips on high-volume write endpoints, and no collisions when we run many instances across regions or hand IDs to background workers before a row is committed. The honest caveat is maturity: early-stage package, essentially no adoption, one maintainer. I would not standardize on it company-wide, and I would not let anything depend on it continuing to exist. I recommend a two-week pilot on one non-critical service, with an explicit fallback — the code is small enough to own ourselves in about half a day — if the maintainer stops maintaining it.
The cost of trying is days. The cost of the status quo is a scaling constraint we would otherwise hit on the critical path. This is plumbing, not a competitive bet, and I'd rather buy two days of plumbing than spend a sprint reinventing it."
For engineering:
"jetcod/eloquent-keygen is an Eloquent adapter over godruoyi/php-snowflake. Prefer the Snowflake trait over extending Jetcod\Eloquent\Model — it keeps a third-party base class out of our model hierarchy and makes the fallback (copying the trait into our own codebase) trivial. The per-model snowflake(): bool escape hatch lets us stage rollout service by service and revert without a deploy of the package itself.
What it buys: 64-bit, roughly time-ordered IDs generated client-side, no LAST_INSERT_ID() round-trip, unique across nodes, and IDs available before commit for queued work. Generation now fires on creating, so updates no longer re-trigger it. What it costs: we own worker_id / datacenter_id allocation as a deployment concern — a misconfiguration is a silent collision rather than an exception, so it needs a deliberate per-environment env strategy and a review checkpoint, not a copy-pasted default of 1. We also own version pinning and the BIGINT UNSIGNED schema change ahead of rollout, plus a decision on public-facing identifiers so we don't leak timestamps and node identity into URLs.
Ask: one service, one non-critical table, two weeks. Success criteria are measurable — write-path latency and zero collision incidents — and the exit is deleting a use statement."
How can I help you explore Laravel packages today?