dobron/laravel-db-enum-generator
Laravel package that generates PHP enum classes from database column values, keeping enum cases in sync with stored data. Useful for replacing magic strings with type-safe enums in models, validation rules, and forms.
const STATUS_ACTIVE = 'active' is a silent-drift risk against the DB. This shifts a recurring, low-severity bug class (typo'd status strings, values present in DB but missing in code, casing mismatches) into a generated, diffable artifact — a measurable reduction in support tickets and incident noise for admin/reporting features.ENUM/VARCHAR columns and generate code from them — a genuine sequencing decision that affects how much schema churn we commit to this quarter.Adopt (or fork) when:
ENUM columns and/or small reference tables whose values are authoritative in the database, not in migrations we control.Look elsewhere or build in-house when:
app/Console/Commands with a test, not as a Composer dependency on a critical path — and definitely not something to pin a platform strategy to.Rule::enum), API serialization, labels/localization, or TypeScript type parity for a frontend, compose purpose-built tools instead; this only emits PHP.To executives (one paragraph): This is a small, free, MIT-licensed utility that generates PHP enum classes directly from our database schema. It is not a platform bet — it is a low-cost accelerator for a specific, unglamorous chore: keeping status and type values in code synchronized with the database. The expected return is fewer small defects from typo'd or stale string constants and faster onboarding onto legacy parts of the schema. Because the project has minimal community traction and no recent release, I recommend we spend roughly one engineer-day to vendor the command into our own codebase rather than take a runtime dependency, so we capture the benefit with zero long-term maintenance exposure. Decision requested: approve the one-day spike; success is measured by whether it removes the manual "update the constants" step from our release checklist.
To engineering: The command reads enum columns and reference tables and emits backed enums, deleting a class of drift bugs and giving us IDE autocomplete and static analysis on domain values. Run it as an explicit, committed step — never in CI against a live database — and add a test asserting generated output matches the schema so drift surfaces as a failing build rather than a production bug. Two caveats to plan around: the upstream package is effectively unmaintained (last release September 2023), so fork it into app/Console/Commands with our own tests; and it only covers PHP, so validation rules, labels, and any frontend type generation remain separate workstreams. Do not let generated enums become the de facto contract for API payloads without an explicit serialization decision.
How can I help you explore Laravel packages today?